/* Transportability Assignment */ /* There are 3 datasets associated with this assignment: "studydata.dta"-- data that was collected during the trial "targetdata.dta"--data observed in the target population "truth.dta"-- hypothetical data representing what would have happened had the study been conducted in the target population. */ clear set more off /* Question 1: Open the trial dataset and estimate the risk difference of being assigned to the intervention compared to being assigned to the standard of care. */ use "studydata.dta", clear logit y i.tx, or margins, dydx(tx) /* Question 2: Append the observed target data to the trial dataset. Create a variable named "sel" to indicate whether each observation came from the trial or target data. Make sure the "sel" variable is coded as 1 for those in the trial population and 0 for those in the target population. */ append using "targetdata.dta", generate(sel) recode sel (1=0) (0=1) /* Question 3: Compare the distribution of family support, education, and distance between the trial and target populations. What do you notice? */ foreach var in dist famsup edu { tab `var' sel, col } /* Transporting to the target population: First, we need to construct the weights. Because we are transporting to a fully external population, we use inverse odds (rather than probability) of selection weights. We first create the weights by estimating each of the components of the weights: */ /* 4a. What is the average probability of being included in the study population? Save this value as the variable "num" */ egen num=mean(sel) /* 4b. We now need to know each individual's predicted probability of being included in the study population given their covariates. To do this, fit a logistic regression with sel as the outcome, and the effect modifiers as predictors. Include an interaction term between distance and family support. Then use the predict command after the regression to get the predicted probabilities of selection for each person. Create a variable called "ps" to store these predictions. */ logit sel i.dist##i.famsup i.edu predict ps, p /* 4c. Construct the weights according to the following formula: ((1-ps)/ps)*(num/(1-num)) Then manually set the weight = 0 for everyone in the target population. */ gen wt=((1-ps)/ps)*(num/(1-num)) replace wt=0 if sel==0 /* Question 5. Transport the effect of the treatment on the outcome using the weights constructed in part 3. Use margins again to get the risk difference. */ logit y i.tx [pweight=wt], or margins, dydx(tx) /* Question 6: Because this is a simulation, we can check to see how close we are to the truth. Open the dataset called "truth.dta". Estimate the true risk difference in the target population. How does your transported estimate compare to the truth. Notice the standard errors/width of your confidence intervals in each. */ use "truth.dta", clear logit y i.tx, or margins, dydx(tx)