People.duke.edu



Chapter 2: STATA CodeSample dataset codebook:treat = Binary indicator of treatment versus control groupx1-x5 = continuous confounders associated with Treatcont_out = Continuous outcome of interestbin_out = Binary outcome of interestEstimating the propensity score in STATA with logistic regressionSTATA> logistic treat x1 x2 x3 x4 x5STATA> predict pscoreMATCHING USING PSMATCH2 PACKAGE// Install psmatch2.ado fileSTATA> findit psmatch2// Sort individuals randomly before matching// Set random seed prior to psmatch2 to ensure replication STATA> set seed 1234STATA> generate sort_id = uniform()STATA> sort sort_idK:1 matching, with and without replacement// 1:1 matching with replacement, estimate PS with logistic regressionSTATA> psmatch2 treat x1 x2 x3 x4 x5, logit// 2:1 matching without replacementSTATA> psmatch2 treat x1 x2 x3 x4 x5, logit noreplace n(2)// 2:1 matching with replacement and caliper, PS previously estimatedSTATA> psmatch2 treat, pscore(pscore) n(2) cal(0.20)// Mahalanobis matching with caliperSTATA> psmatch2 treat, mahal(x1 x2 x3 x4 x5) cal(0.10)Radius matching STATA> psmatch2 treat x1 x2 x3 x4 x5, logit radius caliper(0.10)Kernel matching// Kernel matching, PS estimated with logistic regressionSTATA> psmatch2 treat x1 x2 x3 x4 x5, kernel logit// Perform kernel matching, bandwidth=0.10STATA> psmatch2 treat x1 x2 x3 x4 x5, kernel logit bwidth(0.10)// Estimate ATT for outcome variable(s)STATA> psmatch2 treat x1 x2 x3 x4 x5, kernel outcome(cont_out)Effect estimates// ATT (default estimand) for both outcome variablesSTATA> psmatch2 treat x1 x2 x3 x4 x5, outcome(cont_out bin_out) logit // Regression approach: Equivalent to ATT estimates from psmatch2// First generate weights from psmatch2STATA> psmatch2 treat x1 x2 x3 x4 x5, logit STATA> regress cont_out treat [iweight=_weight] if _weight!=.// Regression including covariates STATA> regress cont_out treat x1 x2 x3 x4 x5 [iweight=_weight] if _weight!=.Balance diagnostics// Balance table and plotSTATA> pstest x1 x2 x3 x4 x5, both graphMATCHING USING TEFFECTS (STATA 13)Nearest neighbor matching // 1:1 Nearest Neighbor Matching with replacement, estimate ATT effect STATA> teffects psmatch (cont_out)(treat x1 x2 x3 x4 x5), nn(1) atet// 2:1 Nearest Neighbor Matching with replacement, estimate ATT effect STATA> teffects psmatch (cont_out)(treat x1 x2 x3 x4 x5), nn(2) atetMahalanobis matching// 1:1 Mahalanobis matching, ATT effectSTATA> teffects nnmatch (cont_out x1 x2 x3 x4 x5) (treat), atet MATCHING USING CEM PACKAGECoarsened exact matching/* install cem package STATA> findit cem/* CEM with automatic binning STATA> cem x1 x2 x3 x4 x5, treatment(treat)/* CEM with user-specified cutpoints for x3STATA> cem x1 x2 x3 (0 1.5 4 7 9 14) x4 x5, treatment(treat)/* Estimate treatment effects using weights since variable-ratioSTATA> regress cont_out treat x1 x2 x3 x4 x5 [iweight=cem_weights]/* Restrict so that all strata contain the same number of treated and controls; no weights necessary in final analysis STATA> cem x1 x2 x3 x4 x5, treatment(treat) k2k/* Estimate treatment effects; no weightingSTATA> regress cont_out treat x1 x2 x3 x4 x5PROPENSITY SCORE WEIGHTING, PARAMETRIC PS ESTIMATION// Estimate the propensity score with logistic regressionSTATA> logistic treat x1 x2 x3 x4 x5STATA> predict pscore// Calculate ATE propensity score weights (IPTW)STATA> gen w_ate = treat/pscore + (1-treat)/(1-pscore)// Use ATE weights as probability weights in final analysisSTATA> svyset [pw=w_ate]STATA> svy: regress cont_out treat x1 x2 x3 x4 x5 // Calculate ATT propensity score weightsSTATA> gen w_att = treat + (1-treat)*(pscore/(1-pscore))// Use ATT weights as probability weights in final analysisSTATA> svyset [pw=w_att]STATA> svy: regress cont_out treat x1 x2 x3 x4 x5 SUBCLASSIFICATION Creating 5 propensity score subclasses// After generating propensity score, can create quintilesSTATA> xtile pscore_5 = pscore, nq(5)Estimating subclass-specific and overall effect estimates// Binary outcome: Mantel-Haenszel stratified analysis STATA> cc bin_out treat, by(pscore_5) bd// Continuous outcome: Van Elteren test (Stratified Wilcoxon rank sum)/* install Van Elteren package STATA> findit vanelterenSTATA> vanelteren cont_out, by(treat) strata(pscore_5) ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download