Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL for Average Treatment Effect

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL for Average Treatment Effect. Start with the requirements and the three tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Tempus AI is evaluating a new drug using a clinical outcomes cohort. Write a PostgreSQL query to estimate the unadjusted average treatment effect by comparing the mean post-treatment outcome for patients receiving the new drug with the mean outcome for control patients.

Requirements

  1. Join patients, treatment assignments, and outcomes using the patient identifier.
  2. Include only patients with a non-null post-treatment outcome.
  3. Return treated and control patient counts, their mean outcomes, and the treatment effect, calculated as treated mean minus control mean. Round numeric results to two decimal places.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient name
cancer_typeVARCHAR(50)Cancer classification
treatment_assignments
ColumnTypeDescription
assignment_idPKINTUnique treatment assignment identifier
patient_idINTAssigned patient
treatment_groupVARCHAR(20)Treatment group, either new_drug or control
outcomes
ColumnTypeDescription
outcome_idPKINTUnique outcome identifier
patient_idINTPatient associated with the outcome
outcome_typeVARCHAR(50)Clinical outcome measure
outcome_scoreDECIMAL(8,2)Post-treatment outcome score
Tablespatientstreatment_assignmentsoutcomes
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results