. /* Setup Data */
. webuse cattaneo2, clear
(Excerpt from Cattaneo (2010) Journal of Econometrics 155: 138–154)
. keep bweight mage mbsmoke prenatal1 mmarried fbaby
. gen id = _n
. order id
.
. /* Store Duplicate Data */
. tempfile copy
. save `copy'
file /var/folders/62/51hy7j9958xd03txmytygwwc0000gn/T//S_57805.000001 saved as .dta format
.
. /* Matching Step */
. teffects nnmatch (bweight mage prenatal1 mmarried fbaby) (mbsmoke), nn(1) gen(match) level(99)
Treatment-effects estimation Number of obs = 4,642
Estimator : nearest-neighbor matching Matches: requested = 1
Outcome model : matching min = 1
Distance metric: Mahalanobis max = 139
| AI robust
bweight | Coefficient std. err. z P>|z| [99% conf. interval]
-----------------------+----------------------------------------------------------------
ATE |
mbsmoke |
(Smoker vs Nonsmoker) | -240.3306 28.43006 -8.45 0.000 -313.5616 -167.0997
.
. /* Get Data Into T-Test Format */
. reshape long match, i(id) j(match_num)
(j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
> 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
> 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
> 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 1
> 23 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139)
Data Wide -> Long
Number of observations 4,642 -> 645,238
Number of variables 146 -> 9
j variable (139 values) -> match_num
xij variables:
match1 match2 ... match139 -> match
. drop if missing(match)
(575,801 observations deleted)
. sort id match_num
. rename (id mbsmoke bweight mage prenatal1 mmarried fbaby) =_original
. rename match id
. merge m:1 id using `copy', nogen keep(match)
(variable id was long, now double to accommodate using data's values)
(label YesNo already defined)
(label mmarried already defined)
(label mbsmoke already defined)
Result Number of obs
-----------------------------------------
Not matched 0
Matched 69,437
-----------------------------------------
. rename (id mbsmoke bweight mage prenatal1 mmarried fbaby) =_matched
. sort id_original
.
. /* Average Over Birthweight in Case There Are Ties /
. / Or To Keep Only the First Match Uncomment the Next Line /
. // keep if match_num == 1
. collapse (mean) bweight_matched, by(_original)
.
. /* Hypothesis Test */
. gen effect = cond(mbsmoke_original == "Smoke":mbsmoke, bweight_original - bweight_matched, bweig
> ht_matched - bweight_original)
(value label dereference "Smoke":mbsmoke not found)
. ttest effect = 0, level(99)
One-sample t test
Variable | Obs Mean Std. err. Std. dev. [99% conf. interval]
---------+--------------------------------------------------------------------
effect | 4,642 -153.7954 9.362789 637.9077 -177.9223 -129.6686
mean = mean(effect) t = -16.4262
H0: mean = 0 Degrees of freedom = 4641
Ha: mean < 0 Ha: mean != 0 Ha: mean > 0
Pr(T < t) = 0.0000 Pr(|T| > |t|) = 0.0000 Pr(T > t) = 1.0000