<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Matching | Carlos Mendez</title><link>https://carlos-mendez.org/category/matching/</link><atom:link href="https://carlos-mendez.org/category/matching/index.xml" rel="self" type="application/rss+xml"/><description>Matching</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><copyright>Carlos Mendez</copyright><lastBuildDate>Wed, 29 Apr 2026 00:00:00 +0000</lastBuildDate><image><url>https://carlos-mendez.org/media/icon_huedfae549300b4ca5d201a9bd09a3ecd5_79625_512x512_fill_lanczos_center_3.png</url><title>Matching</title><link>https://carlos-mendez.org/category/matching/</link></image><item><title>Treatment Effects in Stata: A Beginner's Tour of Six Estimators with the Maternal Smoking and Birth Weight Case Study</title><link>https://carlos-mendez.org/post/stata_matching/</link><pubDate>Wed, 29 Apr 2026 00:00:00 +0000</pubDate><guid>https://carlos-mendez.org/post/stata_matching/</guid><description>&lt;h2 id="1-overview">1. Overview&lt;/h2>
&lt;p>Does maternal smoking during pregnancy &lt;em>cause&lt;/em> lower birth weight, or do smokers and non-smokers simply differ in other ways that happen to predict their babies' birth weights? It is one of the most-studied questions in applied econometrics, and the honest answer depends entirely on how we adjust for the differences between the two groups. In this tutorial we use Stata&amp;rsquo;s &lt;code>teffects&lt;/code> family of commands to walk through &lt;strong>six different treatment-effects estimators&lt;/strong> on a single dataset &amp;mdash; 4,642 mother-infant pairs from the Cattaneo (2010) study &amp;mdash; and watch each one wrestle with the same question.&lt;/p>
&lt;p>The six estimators take three different routes. &lt;strong>Regression adjustment&lt;/strong> models the outcome (birth weight). &lt;strong>Inverse-probability weighting&lt;/strong> and &lt;strong>propensity-score matching&lt;/strong> model the treatment (smoking). &lt;strong>IPWRA&lt;/strong>, &lt;strong>AIPW&lt;/strong>, and &lt;strong>nearest-neighbor matching&lt;/strong> combine ideas from both sides. By the end of the post you will see how their answers agree, where they differ, and how to read each output panel without flinching.&lt;/p>
&lt;p>The pedagogical hook is that we already have a clear (but biased) reference number to anchor the tour. A naive comparison of means says smokers' babies weigh &lt;strong>275 grams less&lt;/strong> than non-smokers'. Every adjusted estimator we run will return a smaller number, and the gap between &lt;strong>−275 g&lt;/strong> (naive) and what we eventually settle on (around &lt;strong>−230 g&lt;/strong>) is exactly what causal-inference machinery buys us. That gap is the bias we would have if we treated this observational dataset as if it came from a randomized experiment. Watching it shrink is the whole pedagogical point.&lt;/p>
&lt;h3 id="learning-objectives">Learning objectives&lt;/h3>
&lt;p>By the end of this tutorial you will be able to:&lt;/p>
&lt;ol>
&lt;li>State the &lt;strong>potential-outcomes framework&lt;/strong> in plain English and define ATE and ATT.&lt;/li>
&lt;li>Explain the three &lt;strong>identification assumptions&lt;/strong> that all six estimators rely on: conditional independence (unconfoundedness), overlap, and SUTVA.&lt;/li>
&lt;li>Implement and interpret &lt;strong>regression adjustment (RA)&lt;/strong>, &lt;strong>inverse-probability weighting (IPW)&lt;/strong>, &lt;strong>IPWRA&lt;/strong>, &lt;strong>AIPW&lt;/strong>, &lt;strong>nearest-neighbor matching (NNM)&lt;/strong>, and &lt;strong>propensity-score matching (PSM)&lt;/strong> in Stata using the &lt;code>teffects&lt;/code> suite.&lt;/li>
&lt;li>Recreate RA and IPW &lt;strong>by hand&lt;/strong> with &lt;code>regress&lt;/code> and &lt;code>logistic&lt;/code>, so the canned commands stop feeling magical.&lt;/li>
&lt;li>Diagnose &lt;strong>propensity-score overlap&lt;/strong> with &lt;code>teffects overlap&lt;/code> and read what it tells you about whether your comparison is credible.&lt;/li>
&lt;li>Compare estimators in a &lt;strong>forest plot&lt;/strong> and decide which differences matter.&lt;/li>
&lt;li>Explain when ATE and ATT can diverge &amp;mdash; and what it means when they do.&lt;/li>
&lt;li>Identify the limits of the design and propose &lt;strong>next steps&lt;/strong> when conditional independence is doubtful.&lt;/li>
&lt;/ol>
&lt;p>The companion &lt;code>analysis.do&lt;/code> file linked at the top of this page runs every estimator in this tutorial end-to-end. Open it side-by-side as you read.&lt;/p>
&lt;h2 id="2-the-case-study-maternal-smoking-and-birth-weight">2. The case study: maternal smoking and birth weight&lt;/h2>
&lt;p>We work with &lt;code>cattaneo2.dta&lt;/code>, a dataset of 4,642 singleton births popularized by Cattaneo (2010). The outcome of interest is &lt;code>bweight&lt;/code> (infant birth weight, measured in grams) and the treatment is &lt;code>mbsmoke&lt;/code> (1 if the mother smoked during pregnancy, 0 otherwise). The remaining variables are pre-treatment characteristics that plausibly affect both the smoking decision and the eventual birth weight.&lt;/p>
&lt;p>The diagram below sketches the inferential challenge. We &lt;em>observe&lt;/em> whether each mother smoked and how much her baby weighed, but the same characteristics that drive the smoking decision also drive birth weight directly &amp;mdash; so the simple comparison conflates the effect of smoking with the effect of those characteristics.&lt;/p>
&lt;pre>&lt;code class="language-mermaid">flowchart LR
X[&amp;quot;X: maternal traits&amp;lt;br/&amp;gt;(age, education, marital,&amp;lt;br/&amp;gt;prenatal care, etc.)&amp;quot;] --&amp;gt; D[&amp;quot;D: maternal smoking&amp;lt;br/&amp;gt;(mbsmoke)&amp;quot;]
X --&amp;gt; Y[&amp;quot;Y: birth weight&amp;lt;br/&amp;gt;(bweight)&amp;quot;]
D --&amp;gt; Y
style X fill:#6a9bcc,stroke:#141413,color:#fff
style D fill:#d97757,stroke:#141413,color:#fff
style Y fill:#00d4c8,stroke:#141413,color:#141413
linkStyle 0,1,2 stroke:#141413,stroke-width:1.5px
&lt;/code>&lt;/pre>
&lt;p>Read the diagram from left to right. Maternal characteristics &lt;code>X&lt;/code> (steel blue) influence both the &lt;em>decision&lt;/em> to smoke &lt;code>D&lt;/code> (warm orange) and the &lt;em>outcome&lt;/em> &lt;code>Y&lt;/code> &amp;mdash; birth weight (teal). The arrow &lt;code>D → Y&lt;/code> is the causal effect we want to isolate. The arrows &lt;code>X → D&lt;/code> and &lt;code>X → Y&lt;/code> together form the &lt;strong>back-door path&lt;/strong> that contaminates a naive comparison: if we just compare smokers to non-smokers, we are picking up the differences in &lt;code>X&lt;/code> between the two groups in addition to the direct effect of smoking. Every method in this tutorial blocks the back-door path in a different way.&lt;/p>
&lt;p>The variables we will use are summarised below.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Variable&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Role&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>bweight&lt;/code>&lt;/td>
&lt;td>int&lt;/td>
&lt;td>Outcome (Y)&lt;/td>
&lt;td>Infant birth weight in grams&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>mbsmoke&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Treatment (D)&lt;/td>
&lt;td>1 if the mother smoked during pregnancy, 0 otherwise&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>mage&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Confounder (X)&lt;/td>
&lt;td>Mother&amp;rsquo;s age at delivery, in years&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>mmarried&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Confounder (X)&lt;/td>
&lt;td>1 if the mother is married&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>fage&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Confounder (X)&lt;/td>
&lt;td>Father&amp;rsquo;s age, in years&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>medu&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Confounder (X)&lt;/td>
&lt;td>Mother&amp;rsquo;s years of education&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>prenatal1&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Confounder (X)&lt;/td>
&lt;td>1 if the first prenatal visit was in the first trimester&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>fbaby&lt;/code>&lt;/td>
&lt;td>byte&lt;/td>
&lt;td>Confounder (X)&lt;/td>
&lt;td>1 if this is the mother&amp;rsquo;s first baby&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>These six covariates are pre-treatment by construction (they are determined before the smoking decision matters for birth weight), which is the basic discipline of a credible adjustment set. We will not always use &lt;em>all&lt;/em> six in every model, because different methods have different conventions, but each variable in this list is in the running.&lt;/p>
&lt;h2 id="3-the-potential-outcomes-framework">3. The potential-outcomes framework&lt;/h2>
&lt;p>Causal inference is easier to reason about once you adopt the &lt;strong>potential-outcomes&lt;/strong> language popularized by Donald Rubin. The mental shift is to imagine, for every mother in the sample, &lt;em>two parallel-universe&lt;/em> birth weights &amp;mdash; one if she smoked, one if she didn&amp;rsquo;t.&lt;/p>
&lt;h3 id="31-the-two-potential-outcomes">3.1 The two potential outcomes&lt;/h3>
&lt;p>For every mother $i$, let $Y_i(1)$ denote the birth weight of her baby in the universe where she smokes, and $Y_i(0)$ denote the birth weight in the universe where she doesn&amp;rsquo;t. The individual treatment effect is the difference:&lt;/p>
&lt;p>$$\tau_i = Y_i(1) - Y_i(0)$$&lt;/p>
&lt;p>In words, $\tau_i$ is the gap, in grams, between the two parallel-universe outcomes for the same mother &amp;mdash; exactly the answer we would want if we could run a randomized experiment on her individually. The formal challenge is the &lt;strong>fundamental problem of causal inference&lt;/strong>: we only ever observe one of the two potential outcomes for any given mother. If she smoked, we see $Y_i(1)$. If she didn&amp;rsquo;t, we see $Y_i(0)$. The other potential outcome is missing, period.&lt;/p>
&lt;p>The diagram below visualizes the challenge.&lt;/p>
&lt;pre>&lt;code class="language-mermaid">flowchart LR
subgraph M[&amp;quot;Mother i&amp;quot;]
Y1[&amp;quot;Y_i(1):&amp;lt;br/&amp;gt;weight if smoker&amp;quot;]
Y0[&amp;quot;Y_i(0):&amp;lt;br/&amp;gt;weight if non-smoker&amp;quot;]
end
M --&amp;gt; O[&amp;quot;We observe&amp;lt;br/&amp;gt;only ONE&amp;quot;]
O --&amp;gt; Q[&amp;quot;Other is&amp;lt;br/&amp;gt;missing → must&amp;lt;br/&amp;gt;be estimated&amp;quot;]
style Y1 fill:#d97757,stroke:#141413,color:#fff
style Y0 fill:#6a9bcc,stroke:#141413,color:#fff
style M fill:#fafafa,stroke:#141413,color:#141413
style O fill:#00d4c8,stroke:#141413,color:#141413
style Q fill:#e8e8e8,stroke:#141413,color:#141413
linkStyle 0,1 stroke:#141413,stroke-width:1.5px
&lt;/code>&lt;/pre>
&lt;p>The fundamental problem is what makes causal inference a &lt;strong>missing-data problem in disguise&lt;/strong>. Every estimator in this tutorial is, at heart, a different way of imputing the missing potential outcome. RA imputes it with a regression model. IPW imputes it implicitly by re-weighting. Matching imputes it with the actual outcome of a similar but un-treated unit.&lt;/p>
&lt;h3 id="32-ate-versus-att">3.2 ATE versus ATT&lt;/h3>
&lt;p>Because we cannot recover individual effects, we settle for &lt;em>averages&lt;/em>. The two most common averages are the &lt;strong>average treatment effect&lt;/strong> (ATE) and the &lt;strong>average treatment effect on the treated&lt;/strong> (ATT):&lt;/p>
&lt;p>$$\tau_{ATE} = E[Y(1) - Y(0)]$$&lt;/p>
&lt;p>$$\tau_{ATT} = E[Y(1) - Y(0) \mid D = 1]$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> The ATE is the average effect we would expect if we randomly drew a mother from the population and forced her to smoke (vs. not smoke). The ATT is the average effect of smoking &lt;em>for the mothers who actually smoked&lt;/em>. They answer different policy questions. ATE answers &amp;ldquo;what would happen if smoking became universal?&amp;rdquo; ATT answers &amp;ldquo;what is happening to those who currently smoke?&amp;rdquo;&lt;/p>
&lt;p>In this tutorial every method that supports both estimands will report both. Most methods give us an ATE that is slightly more negative than the ATT, because mothers who actually smoke happen to differ from the average mother in ways that, in this dataset, dampen the harm. We will see this divergence concretely in §11 when we compare results across methods.&lt;/p>
&lt;h3 id="33-why-a-naive-comparison-fails">3.3 Why a naive comparison fails&lt;/h3>
&lt;p>If smoking had been randomly assigned to mothers, we could estimate the ATE as the simple difference of group means: $\bar{Y}_{D=1} - \bar{Y}_{D=0}$. With observational data this naive comparison fails because the treatment groups are not exchangeable &amp;mdash; they differ on the covariates &lt;code>X&lt;/code> that themselves drive birth weight. Concretely, mothers who smoke during pregnancy are on average less educated, less likely to be married, and more likely to skip the first-trimester prenatal visit; each of those characteristics is independently associated with lower birth weight. The naive gap therefore mixes the genuine effect of smoking with the &lt;strong>selection bias&lt;/strong> that arises from those covariate differences. The job of the six methods we are about to study is to subtract that selection bias.&lt;/p>
&lt;h2 id="4-the-identification-assumptions">4. The identification assumptions&lt;/h2>
&lt;p>Every method in this tutorial relies on three assumptions. They are not free; if any one of them fails badly, no amount of clever adjustment will recover the truth.&lt;/p>
&lt;p>&lt;strong>Assumption 1 (Conditional independence / unconfoundedness):&lt;/strong>&lt;/p>
&lt;p>$$\{Y(0), Y(1)\} \perp D \mid X$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> Conditional on the observed covariates &lt;code>X&lt;/code>, the treatment &lt;code>D&lt;/code> is &amp;ldquo;as good as randomly assigned&amp;rdquo; in the sense that it is independent of the potential outcomes. In our case this means that, &lt;em>among mothers who look identical on age, education, marital status, prenatal care, parity, and father&amp;rsquo;s age&lt;/em>, smoking is statistically the same as a coin flip with respect to birth-weight potential outcomes. This is a strong assumption. It is not testable directly. It is plausible only to the extent that &lt;code>X&lt;/code> captures the &lt;em>systematic&lt;/em> drivers of selection into smoking.&lt;/p>
&lt;p>&lt;strong>Assumption 2 (Overlap, also known as positivity):&lt;/strong>&lt;/p>
&lt;p>$$0 &amp;lt; e(X) &amp;lt; 1, \quad \text{where} \quad e(X) = \Pr(D = 1 \mid X)$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> For every value of &lt;code>X&lt;/code> we observe in the data, both smokers and non-smokers exist. If there is some combination of covariates &amp;mdash; say, well-educated mothers over 35 with first-trimester prenatal care &amp;mdash; where literally nobody smokes, we cannot make a credible counterfactual prediction for those mothers. Overlap is testable, and we will check it visually in §10 with &lt;code>teffects overlap&lt;/code>.&lt;/p>
&lt;p>&lt;strong>Assumption 3 (SUTVA &amp;mdash; Stable Unit Treatment Value Assumption):&lt;/strong>&lt;/p>
&lt;p>The treatment of one mother does not affect the outcome of another, and there is &amp;ldquo;only one version&amp;rdquo; of the treatment. SUTVA fails if, for instance, smoking is socially contagious within neighborhoods (one woman&amp;rsquo;s smoking causes her friend to smoke too) or if &amp;ldquo;smoking&amp;rdquo; hides multiple intensities (two cigarettes a day vs. two packs) that we are pooling. For our purposes SUTVA is plausible because births are biologically independent and we are working with a binary smoking indicator.&lt;/p>
&lt;p>If conditional independence fails, the methods are &lt;em>all&lt;/em> biased in the same direction &amp;mdash; including the doubly robust ones. If overlap fails, the comparison is partially undefined. If SUTVA fails, the estimand itself becomes fuzzy. None of the six estimators below repairs an assumption violation; they only correct for things &lt;code>X&lt;/code> can see. We will return to this point in the limitations section.&lt;/p>
&lt;h2 id="5-loading-and-exploring-the-data">5. Loading and exploring the data&lt;/h2>
&lt;p>We start in Stata by loading the dataset directly from a public URL, so that anybody can reproduce the analysis without downloading files manually. The &lt;code>describe&lt;/code> command surfaces variable types and labels; &lt;code>summarize&lt;/code> gives us means and ranges.&lt;/p>
&lt;pre>&lt;code class="language-stata">* Load the dataset directly from the web
use &amp;quot;https://github.com/quarcs-lab/data-open/raw/master/ametrics/cattaneo2.dta&amp;quot;, clear
* Describe and summarize the variables of interest
describe bweight mbsmoke mage mmarried fage medu prenatal1 fbaby
summarize bweight mbsmoke mage mmarried fage medu prenatal1 fbaby
* Treatment prevalence and group means
tab mbsmoke
tab mbsmoke, summarize(bweight)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
bweight | 4,642 3361.68 578.8196 340 5500
mbsmoke | 4,642 .1861267 .3892508 0 1
mage | 4,642 26.50452 5.619026 13 45
mmarried | 4,642 .7197329 .4491722 0 1
fage | 4,642 27.26713 9.354411 0 60
medu | 4,642 12.68957 2.520661 0 17
prenatal1 | 4,642 .8013787 .3990052 0 1
fbaby | 4,642 .4379578 .4961893 0 1
1 if mother | Summary of Infant birthweight (grams)
smoked | Mean Std. dev. Freq.
------------+------------------------------------
Nonsmoker | 3412.91 570.69 3,778
Smoker | 3137.66 560.89 864
------------+------------------------------------
Total | 3361.68 578.82 4,642
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> The analysis sample has 4,642 singleton births. Smokers are a minority &amp;mdash; 864 mothers, or &lt;strong>18.6%&lt;/strong> of the sample &amp;mdash; which is exactly why a naive comparison is risky: when treated and control groups differ in size &lt;em>and&lt;/em> in observable characteristics, a difference of means is dominated by whichever group has more variation in the confounders. The raw mean birth weight is 3,412.9 g among non-smokers and 3,137.7 g among smokers, a 275 g gap. Average maternal age is 26.5, 72% are married, 80% had a first-trimester prenatal visit, and average maternal education is 12.7 years. We will revisit each of these covariates as confounders below.&lt;/p>
&lt;p>Before we estimate any treatment effect, it is useful to &lt;em>see&lt;/em> the raw outcome distribution. The figure below plots a kernel density of &lt;code>bweight&lt;/code>, separately for smokers and non-smokers, with no adjustment of any kind.&lt;/p>
&lt;pre>&lt;code class="language-stata">twoway ///
(kdensity bweight if mbsmoke==0, lcolor(&amp;quot;106 155 204&amp;quot;) lwidth(medthick)) ///
(kdensity bweight if mbsmoke==1, lcolor(&amp;quot;217 119 87&amp;quot;) lwidth(medthick)) ///
, title(&amp;quot;Birth Weight by Maternal Smoking Status&amp;quot;) ///
xtitle(&amp;quot;Infant birth weight (grams)&amp;quot;) ytitle(&amp;quot;Density&amp;quot;) ///
legend(order(1 &amp;quot;Non-smokers&amp;quot; 2 &amp;quot;Smokers&amp;quot;))
graph export &amp;quot;stata_matching_density_bweight.png&amp;quot;, replace width(2400)
&lt;/code>&lt;/pre>
&lt;p>&lt;img src="stata_matching_density_bweight.png" alt="Kernel density of infant birth weight by maternal smoking status. Non-smokers' distribution is centered around 3,400 grams; smokers' distribution is shifted left, centered around 3,150 grams.">&lt;/p>
&lt;p>&lt;strong>Interpretation.&lt;/strong> Smokers' density (warm orange) sits visibly to the left of non-smokers' density (steel blue), with the modes separated by roughly 250 grams. Both distributions are unimodal, roughly bell-shaped, and have similar spreads. The picture is striking, but it is &lt;em>exactly&lt;/em> the picture confounding produces: it shows us nothing about whether the leftward shift is caused by smoking, by the other characteristics that distinguish smoking from non-smoking mothers, or by some mixture. The next eight sections all aim to peel apart that mixture.&lt;/p>
&lt;h2 id="6-a-roadmap-to-six-estimators">6. A roadmap to six estimators&lt;/h2>
&lt;p>The six methods we will run can be organized by which side of the data they model. Some model the &lt;em>outcome&lt;/em>, some the &lt;em>treatment&lt;/em>, some both, and matching estimators sidestep modeling and work directly on the data. The diagram below is the mental map we will return to as we add each method.&lt;/p>
&lt;pre>&lt;code class="language-mermaid">flowchart TD
Start[&amp;quot;What do we model?&amp;quot;]
Start --&amp;gt; Outcome[&amp;quot;Outcome model&amp;lt;br/&amp;gt;only&amp;quot;]
Start --&amp;gt; Treatment[&amp;quot;Treatment&amp;lt;br/&amp;gt;(propensity) model&amp;lt;br/&amp;gt;only&amp;quot;]
Start --&amp;gt; Both[&amp;quot;Both models&amp;lt;br/&amp;gt;(doubly robust)&amp;quot;]
Start --&amp;gt; Direct[&amp;quot;Match directly&amp;lt;br/&amp;gt;on covariates&amp;quot;]
Outcome --&amp;gt; RA[&amp;quot;1. Regression Adjustment&amp;lt;br/&amp;gt;(RA)&amp;quot;]
Treatment --&amp;gt; IPW[&amp;quot;2. Inverse-Probability&amp;lt;br/&amp;gt;Weighting (IPW)&amp;quot;]
Treatment --&amp;gt; PSM[&amp;quot;6. Propensity-Score&amp;lt;br/&amp;gt;Matching (PSM)&amp;quot;]
Both --&amp;gt; IPWRA[&amp;quot;3. IPWRA&amp;quot;]
Both --&amp;gt; AIPW[&amp;quot;4. AIPW&amp;quot;]
Direct --&amp;gt; NNM[&amp;quot;5. Nearest-Neighbor&amp;lt;br/&amp;gt;Matching (NNM)&amp;quot;]
style Start fill:#141413,stroke:#141413,color:#fff
style Outcome fill:#6a9bcc,stroke:#141413,color:#fff
style Treatment fill:#d97757,stroke:#141413,color:#fff
style Both fill:#00d4c8,stroke:#141413,color:#141413
style Direct fill:#fafafa,stroke:#141413,color:#141413
style RA fill:#6a9bcc,stroke:#141413,color:#fff
style IPW fill:#d97757,stroke:#141413,color:#fff
style PSM fill:#d97757,stroke:#141413,color:#fff
style IPWRA fill:#00d4c8,stroke:#141413,color:#141413
style AIPW fill:#00d4c8,stroke:#141413,color:#141413
style NNM fill:#fafafa,stroke:#141413,color:#141413
linkStyle 0,1,2,3,4,5,6,7,8,9 stroke:#141413,stroke-width:1.5px
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>How to read the taxonomy.&lt;/strong> RA is the only estimator that relies &lt;em>purely&lt;/em> on an outcome model; if that model is wrong, RA is biased. IPW and PSM both lean on a model of the treatment (also called the propensity score); if that model is wrong, they are biased. IPWRA and AIPW combine both kinds of model and inherit the &lt;strong>doubly robust&lt;/strong> property: they remain consistent if &lt;em>either&lt;/em> the outcome model or the treatment model is correctly specified &amp;mdash; you only need one of two to be right. NNM is the odd one out: it does not fit a parametric model at all but instead matches each treated mother directly to the most similar untreated mother in covariate space. Before we run any method, we will also estimate a &lt;strong>naive baseline&lt;/strong> (a one-variable regression with no covariates) so we have a number to put the adjustments against.&lt;/p>
&lt;p>The companion &lt;code>analysis.do&lt;/code> file estimates each method in roughly 20 seconds. We walk through them one at a time below, and in §11 we line up all six estimates plus the naive baseline in a single forest plot.&lt;/p>
&lt;h2 id="7-the-naive-baseline">7. The naive baseline&lt;/h2>
&lt;p>Before any adjustment, what does an OLS regression with no controls say? This will be our &lt;strong>biased reference point&lt;/strong> &amp;mdash; the answer we get if we treat the data as if it came from a randomized experiment, when in fact it didn&amp;rsquo;t.&lt;/p>
&lt;pre>&lt;code class="language-stata">regress bweight mbsmoke, vce(robust)
estimates store te_naive
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Linear regression Number of obs = 4,642
F(1, 4640) = 168.33
R-squared = 0.0343
------------------------------------------------------------------------------
| Robust
bweight | Coefficient std. err. t P&amp;gt;|t| [95% conf. interval]
-------------+----------------------------------------------------------------
mbsmoke | -275.2519 21.21501 -12.97 0.000 -316.8434 -233.6604
_cons | 3412.912 9.285455 367.55 0.000 3394.708 3431.115
------------------------------------------------------------------------------
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> The unadjusted gap is &lt;strong>−275.3 grams&lt;/strong> (95% CI: [−316.8, −233.7]; t = −12.97). This is the number a journalist who saw only &lt;code>bweight&lt;/code> and &lt;code>mbsmoke&lt;/code> would publish. It is a precise estimate of the wrong quantity: it absorbs both the causal effect of smoking and the contribution of every covariate that differs between smoking and non-smoking mothers. The R² is 3.4% &amp;mdash; smoking alone, without controls, explains only a tiny fraction of birth-weight variation, but the &lt;em>average&lt;/em> gap is estimated very precisely thanks to the large sample. We will see every adjusted estimator pull this number toward zero.&lt;/p>
&lt;h2 id="8-method-1-----regression-adjustment-ra">8. Method 1 &amp;mdash; Regression Adjustment (RA)&lt;/h2>
&lt;p>&lt;strong>Purpose.&lt;/strong> Regression adjustment fits two outcome models, one for smokers and one for non-smokers, and then uses each of them to &lt;em>predict&lt;/em> the outcome for everybody &amp;mdash; producing a predicted potential outcome under treatment and another under control. Averaging the predicted gap gives the ATE.&lt;/p>
&lt;p>&lt;strong>Analogy.&lt;/strong> Imagine you have a class of students and you give half of them a tutoring program. Instead of comparing post-test scores directly (which would conflate the program with the differences between the kids who got it and the kids who didn&amp;rsquo;t), you build two predictive models: one of &amp;ldquo;what score would this student have gotten if tutored?&amp;rdquo; and one of &amp;ldquo;what score would this student have gotten if not tutored?&amp;rdquo;, using their grades, attendance, and so on. You then ask: averaging across the whole class, how much higher are the predicted &amp;ldquo;tutored&amp;rdquo; scores? That difference is the RA estimate of the ATE.&lt;/p>
&lt;p>&lt;strong>Estimand.&lt;/strong> RA targets the ATE (and, with the &lt;code>atet&lt;/code> option, the ATT):&lt;/p>
&lt;p>$$\hat{\tau}_{RA} = \frac{1}{n}\sum_{i=1}^{n}\left[\hat{\mu}_1(X_i) - \hat{\mu}_0(X_i)\right]$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> $\hat{\mu}_d(X)$ is the fitted regression $E[Y \mid D=d, X]$ for treatment arm $d$ &amp;mdash; in code, the prediction from a &lt;code>regress&lt;/code> model fit on the &lt;code>D=d&lt;/code> subsample. RA evaluates both fitted models at every observation&amp;rsquo;s covariates, takes the difference, and averages.&lt;/p>
&lt;p>In Stata, &lt;code>teffects ra&lt;/code> does the whole sequence in one line. We pass two parenthesized blocks: the first specifies the &lt;strong>outcome equation&lt;/strong> (&lt;code>bweight&lt;/code> plus the covariates we want to control for), the second specifies the &lt;strong>treatment indicator&lt;/strong> (&lt;code>mbsmoke&lt;/code>). The &lt;code>pomeans&lt;/code>, &lt;code>ate&lt;/code>, and &lt;code>atet&lt;/code> options switch between the three reportable quantities &amp;mdash; the two potential-outcome means, the ATE, and the ATT.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects ra (bweight mmarried mage prenatal1 fbaby) (mbsmoke), pomeans nolog
teffects ra (bweight mmarried mage prenatal1 fbaby) (mbsmoke), ate nolog
estimates store te_ra
teffects ra (bweight mmarried mage prenatal1 fbaby) (mbsmoke), atet nolog
estimates store te_ra_att
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Treatment-effects estimation Number of obs = 4,642
Estimator : regression adjustment
POmeans |
Nonsmoker | 3403.242 9.525207 357.29 0.000 3384.573 3421.911
Smoker | 3163.603 21.86351 144.70 0.000 3120.751 3206.455
ATE |
mbsmoke |
(Smoker
vs
Nonsmoker) | -239.6392 23.82402 -10.06 0.000 -286.3334 -192.945
ATET |
mbsmoke | -223.3017 22.7422 -9.82 0.000 -267.8755 -178.7278
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> The RA estimate of the ATE is &lt;strong>−239.6 g&lt;/strong> (95% CI: [−286.3, −192.9], z = −10.06). The two potential-outcome means say that, averaged over the entire sample, predicted birth weight is about 3,403 g if no mothers smoked and 3,164 g if all mothers smoked &amp;mdash; the gap between those two numbers is the ATE. The ATT is &lt;strong>−223.3 g&lt;/strong>, slightly closer to zero, meaning that among the women who actually smoked, the model expects smoking to harm their babies somewhat less than it would harm the average baby in the sample. The naive gap of −275 g has just shrunk by 35.6 g, or &lt;strong>13%&lt;/strong>, simply by adjusting for marital status, maternal age, prenatal care, and parity.&lt;/p>
&lt;h3 id="manual-recreation-regression-adjustment-by-hand">Manual recreation: regression adjustment by hand&lt;/h3>
&lt;p>&lt;code>teffects ra&lt;/code> is not a black box. We can rebuild the same number with three commands: fit two ordinary regressions, predict potential outcomes for everybody, and average the gap.&lt;/p>
&lt;pre>&lt;code class="language-stata">* Fit the outcome model on non-smokers only and predict everyone's Y(0)
regress bweight mmarried mage prenatal1 fbaby if mbsmoke==0
predict y0_hat, xb
* Fit the outcome model on smokers only and predict everyone's Y(1)
regress bweight mmarried mage prenatal1 fbaby if mbsmoke==1
predict y1_hat, xb
* Take the difference and average
generate te_i = y1_hat - y0_hat
summarize te_i
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> Variable | Obs Mean Std. dev. Min Max
-------------+---------------------------------------------------------
te_i | 4,642 -239.6392 99.008 -488.4602 8.261719
Manual RA estimate of ATE: -239.64 grams
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> The hand-built RA reproduces the canned &lt;code>teffects ra&lt;/code> ATE to four significant figures (−239.64 g vs. −239.6392 g). The standard deviation of the predicted individual treatment effects (99 g) is large compared with the mean, which tells us that &amp;mdash; &lt;em>if you trust the outcome model&lt;/em> &amp;mdash; the harm of smoking varies substantially across mothers depending on their covariate profile. A handful of mothers (the maximum is +8.3 g) even have positive predicted effects, but those are small and rare. The exact match between the manual and canned versions is the demystification we wanted: &lt;code>teffects ra&lt;/code> is exactly two &lt;code>regress&lt;/code> calls, two &lt;code>predict&lt;/code> statements, and a difference.&lt;/p>
&lt;h2 id="9-method-2-----inverse-probability-weighting-ipw">9. Method 2 &amp;mdash; Inverse-Probability Weighting (IPW)&lt;/h2>
&lt;p>&lt;strong>Purpose.&lt;/strong> Where RA models the outcome, IPW models the &lt;strong>treatment&lt;/strong>. It estimates each mother&amp;rsquo;s propensity to smoke as a function of her covariates, then re-weights every observation by the inverse of that propensity. The reweighted sample mimics what we would have seen if smoking had been randomly assigned.&lt;/p>
&lt;p>&lt;strong>Analogy.&lt;/strong> Think of a survey where rural respondents are under-sampled. To recover the population mean, the standard fix is to up-weight rural respondents proportionally. IPW does the same trick for &lt;em>treatment&lt;/em>: under-represented combinations (e.g., a married 35-year-old smoker, or an unmarried 18-year-old non-smoker) get more weight, so the re-weighted sample looks like a randomized experiment.&lt;/p>
&lt;p>&lt;strong>Estimand.&lt;/strong> IPW targets the ATE (and, with &lt;code>atet&lt;/code>, the ATT):&lt;/p>
&lt;p>$$\hat{\tau}_{IPW} = \frac{1}{n}\sum_i \left[\frac{D_i Y_i}{\hat{e}(X_i)} - \frac{(1-D_i) Y_i}{1-\hat{e}(X_i)}\right]$$&lt;/p>
&lt;p>where the &lt;strong>propensity score&lt;/strong> is&lt;/p>
&lt;p>$$e(X) = \Pr(D = 1 \mid X)$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> Each mother contributes her own outcome, but a smoker (D=1) is up-weighted by 1/$\hat{e}(X)$ &amp;mdash; so an unlikely smoker (small $\hat{e}$) counts a lot &amp;mdash; and a non-smoker is up-weighted by 1/(1−$\hat{e}$). The weighted average of smokers' outcomes, minus the weighted average of non-smokers' outcomes, is the IPW estimate of the ATE.&lt;/p>
&lt;p>In Stata, &lt;code>teffects ipw&lt;/code> accepts a single outcome block (just &lt;code>bweight&lt;/code>, with no covariates inside) followed by the &lt;strong>treatment block&lt;/strong> with the propensity-score covariates. We use a &lt;code>probit&lt;/code> link, which is &lt;code>teffects&lt;/code>&amp;rsquo;s default.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects ipw (bweight) (mbsmoke mmarried mage fbaby medu, probit), pomeans nolog
teffects ipw (bweight) (mbsmoke mmarried mage fbaby medu, probit), ate nolog
estimates store te_ipw
teffects ipw (bweight) (mbsmoke mmarried mage fbaby medu, probit), atet nolog
estimates store te_ipw_att
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Treatment-effects estimation Number of obs = 4,642
Estimator : inverse-probability weights
Treatment model: probit
ATE | -230.906 24.30987 -9.50 0.000 -278.5525 -183.2595
ATET | -219.6338 23.38456 -9.39 0.000 -265.4667 -173.8009
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> IPW gives an ATE of &lt;strong>−230.9 g&lt;/strong> (95% CI: [−278.6, −183.3], z = −9.50). The point estimate is 8.7 g closer to zero than the RA estimate (−239.6 g) and 44 g closer to zero than the naive baseline. The fact that two methods that model entirely different sides of the data &amp;mdash; IPW models smoking, RA models birth weight &amp;mdash; agree to within about ten grams is the first strong signal that the underlying causal effect is real and not an artifact of one model&amp;rsquo;s specification.&lt;/p>
&lt;h3 id="manual-recreation-ipw-by-hand">Manual recreation: IPW by hand&lt;/h3>
&lt;p>We can build IPW by hand in three steps: estimate propensity scores with &lt;code>logistic&lt;/code>, generate IPW weights, and run a &lt;strong>weighted regression&lt;/strong> of &lt;code>bweight&lt;/code> on &lt;code>mbsmoke&lt;/code>. The coefficient on &lt;code>mbsmoke&lt;/code> is then the manual IPW estimate.&lt;/p>
&lt;pre>&lt;code class="language-stata">* Step 1: estimate the propensity score with logistic regression
logistic mbsmoke mmarried mage fbaby medu, nolog
predict ps, p
* Step 2: build IPW weights
generate ipw_w = 1/ps if mbsmoke==1
replace ipw_w = 1/(1-ps) if mbsmoke==0
* Step 3: weighted regression
regress bweight mbsmoke [aweight=ipw_w]
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Logistic regression Number of obs = 4,642
LR chi2(4) = 346.31
Pseudo R2 = 0.0776
Manual IPW estimate (coefficient on mbsmoke): -232.13 grams
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> The logistic propensity model has a likelihood-ratio chi-square of 346.3 on 4 degrees of freedom (p &amp;lt; 0.0001), indicating that observable covariates carry real information about who smokes &amp;mdash; otherwise IPW would have nothing to correct. The pseudo-R² of 7.8% is moderate: covariates explain meaningful but not overwhelming variation in the smoking decision, which is &lt;em>exactly the regime IPW likes&lt;/em> because it implies neither sparse overlap (which would happen with R² near 1) nor pointless reweighting (R² near 0). The manual IPW estimate of −232.1 g is within 1.2 g of the canned probit-IPW (−230.9 g) &amp;mdash; the small difference comes from logit vs. probit and from how &lt;code>teffects&lt;/code> weights the contributions. Method-to-method agreement on the order of 1 gram tells us the two link functions are interchangeable here.&lt;/p>
&lt;p>The figure below shows the propensity-score distributions by treatment status. It is the key diagnostic for IPW: where the two distributions overlap, we have credible reweighting; where they diverge, the inverse weights blow up.&lt;/p>
&lt;p>&lt;img src="stata_matching_propensity_distribution.png" alt="Histogram of estimated propensity scores by maternal smoking status. Both distributions span most of the unit interval, with substantial overlap.">&lt;/p>
&lt;p>&lt;strong>Interpretation.&lt;/strong> Both distributions span most of the unit interval. Non-smokers (steel blue) cluster toward the left (most have a low estimated probability of smoking, consistent with smokers being a minority) but extend well into the high-propensity region; smokers (warm orange) cluster toward the right but extend well into the low-propensity region. There is no obvious zone where one group is absent, which is the visual signature of the &lt;strong>overlap assumption&lt;/strong> holding. Without this overlap, IPW would be unstable &amp;mdash; a non-smoker with $\hat{e}(X) = 0.99$ would get a weight of 100, dominating the weighted mean.&lt;/p>
&lt;h2 id="10-methods-3-and-4-----the-doubly-robust-pair-ipwra-and-aipw">10. Methods 3 and 4 &amp;mdash; The doubly robust pair: IPWRA and AIPW&lt;/h2>
&lt;p>The next two estimators belong to the family of &lt;strong>doubly robust&lt;/strong> methods. They combine an outcome model (like RA) with a treatment model (like IPW) in a way that delivers a consistent estimate of the ATE if &lt;em>either&lt;/em> model is correctly specified. You only need one of two to be right, which is a forgiving property in applied work.&lt;/p>
&lt;h3 id="101-ipwra-----ipw--regression-adjustment">10.1 IPWRA &amp;mdash; IPW + Regression Adjustment&lt;/h3>
&lt;p>&lt;strong>Purpose.&lt;/strong> IPWRA fits the IPW weights, then runs RA &lt;em>with those weights&lt;/em>. If the propensity model is correct, the weighting alone delivers the ATE. If the outcome model is correct, the regression adjustment alone delivers the ATE. If both are correct, IPWRA is efficient. If only one is correct, IPWRA is still consistent.&lt;/p>
&lt;p>&lt;strong>Analogy.&lt;/strong> It is the suspenders-and-belt strategy. You have two candidate corrections for confounding. Combining them in this particular way means that if either one happens to be the right one, your final estimate is right too.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects ipwra (bweight mmarried mage prenatal1 fbaby) ///
(mbsmoke mmarried mage fbaby medu, probit), ate nolog
estimates store te_ipwra
teffects ipwra (bweight mmarried mage prenatal1 fbaby) ///
(mbsmoke mmarried mage fbaby medu, probit), atet nolog
estimates store te_ipwra_att
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">ATE | -231.8723 25.1541 -9.22 0.000 -281.1735 -182.5712
ATET | -220.6476 23.37268 -9.44 0.000 -266.4572 -174.838
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> IPWRA gives an ATE of &lt;strong>−231.9 g&lt;/strong> (95% CI: [−281.2, −182.6]) and an ATT of &lt;strong>−220.6 g&lt;/strong>. Both estimates are essentially indistinguishable from the IPW results (−230.9 g ATE, −219.6 g ATT), differing by less than 1.3 g. That convergence is the doubly robust property paying off in practice: even if our outcome model is misspecified by some unknown amount, the IPW step is mopping up the bias &amp;mdash; and vice versa.&lt;/p>
&lt;h3 id="102-aipw-----augmented-ipw">10.2 AIPW &amp;mdash; Augmented IPW&lt;/h3>
&lt;p>&lt;strong>Purpose.&lt;/strong> AIPW is the &lt;em>efficient&lt;/em> doubly robust estimator. It blends RA and IPW with a particular adjustment that achieves the &lt;strong>semiparametric efficiency bound&lt;/strong> under standard regularity conditions, meaning no other regular estimator can have a smaller asymptotic variance.&lt;/p>
&lt;p>&lt;strong>Estimand.&lt;/strong> AIPW targets the ATE only in &lt;code>teffects aipw&lt;/code>. The estimator can be written as:&lt;/p>
&lt;p>$$\hat{\tau}_{AIPW} = \frac{1}{n}\sum_i \left\{ [\hat{\mu}_1(X_i) - \hat{\mu}_0(X_i)] + \frac{D_i [Y_i - \hat{\mu}_1(X_i)]}{\hat{e}(X_i)} - \frac{(1-D_i)[Y_i - \hat{\mu}_0(X_i)]}{1 - \hat{e}(X_i)} \right\}$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> The first bracketed term is the RA estimator. The next two terms add a propensity-weighted correction based on the &lt;em>residuals&lt;/em> from the outcome model. If the outcome model is exactly right, the residuals are mean-zero and the correction vanishes &amp;mdash; AIPW collapses to RA. If the outcome model is wrong but the propensity model is right, the correction debiases it. So AIPW is RA with an automatic safety net.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects aipw (bweight mmarried mage prenatal1 fbaby) ///
(mbsmoke mmarried mage fbaby medu, probit), ate nolog
estimates store te_aipw
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">ATE | -232.4759 24.83406 -9.36 0.000 -281.1497 -183.802
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> AIPW gives an ATE of &lt;strong>−232.5 g&lt;/strong> (95% CI: [−281.1, −183.8], z = −9.36), almost identical to IPWRA (−231.9 g). The two doubly robust estimators differ by 0.6 g, well within rounding noise. Stata&amp;rsquo;s &lt;code>teffects aipw&lt;/code> does not provide an ATT &amp;mdash; this is a software-implementation detail, not a conceptual limitation of the method, and we will note it in the comparison table. AIPW is the recommended default when both an outcome model and a treatment model are credible, because it inherits the doubly robust property &lt;em>and&lt;/em> attains the efficiency bound.&lt;/p>
&lt;h2 id="11-method-5-----nearest-neighbor-matching-nnm">11. Method 5 &amp;mdash; Nearest-Neighbor Matching (NNM)&lt;/h2>
&lt;p>&lt;strong>Purpose.&lt;/strong> Matching estimators step away from parametric outcome and treatment models entirely. Instead, they ask: for every smoking mother, who is her &lt;strong>statistical twin&lt;/strong> among the non-smoking mothers? Find that twin (or that small set of twins), and compute the difference in birth weights. Average across all the matched pairs.&lt;/p>
&lt;p>&lt;strong>Analogy.&lt;/strong> If you are trying to estimate the effect of attending a private school, NNM is &amp;ldquo;for every private-school student, find a public-school student with the same age, same family income, same parental education, and same standardized-test score from third grade &amp;mdash; then compare their twelfth-grade test scores.&amp;rdquo; The matching does the heavy lifting that a regression would otherwise do.&lt;/p>
&lt;p>&lt;strong>Estimand.&lt;/strong> NNM targets the ATE (and, with &lt;code>atet&lt;/code>, the ATT):&lt;/p>
&lt;p>$$\hat{\tau}_{NNM} = \frac{1}{n}\sum_i (2D_i - 1)\left[Y_i - \frac{1}{M}\sum_{j \in J_M(i)} Y_j\right]$$&lt;/p>
&lt;p>&lt;strong>Read it like this.&lt;/strong> $J_M(i)$ is the set of $M$ nearest neighbors of mother $i$ in the &lt;em>opposite&lt;/em> treatment group, measured by Mahalanobis distance over the covariates. The expression in brackets is the difference between mother $i$&amp;rsquo;s observed outcome and the average outcome of her nearest neighbors. The factor $(2D_i - 1)$ flips the sign so that smokers contribute (smoker outcome − matched non-smoker outcome) and non-smokers contribute (matched smoker outcome − non-smoker outcome). The default &lt;code>M=1&lt;/code> uses a single nearest neighbor.&lt;/p>
&lt;p>In Stata, &lt;code>teffects nnmatch&lt;/code> accepts the outcome variable plus the covariates to match on, then the treatment indicator. The &lt;code>ematch()&lt;/code> option forces &lt;em>exact&lt;/em> matching on a subset of (typically discrete) variables &amp;mdash; here marital status and prenatal care, so we never match a married mother to an unmarried one. The &lt;code>biasadj()&lt;/code> option requests a small-sample bias correction for the continuous matching variables.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects nnmatch (bweight mmarried mage fage medu prenatal1) (mbsmoke), ///
ematch(mmarried prenatal1) biasadj(mage fage medu) ate nolog
estimates store te_nnmatch
teffects nnmatch (bweight mmarried mage fage medu prenatal1) (mbsmoke), ///
ematch(mmarried prenatal1) biasadj(mage fage medu) atet nolog
estimates store te_nnmatch_att
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Estimator : nearest-neighbor matching Matches: requested = 1
Distance metric: Mahalanobis max = 16
ATE | -210.0558 29.32803 -7.16 0.000 -267.5377 -152.5739
ATET | -238.5204 30.41661 -7.84 0.000 -298.1359 -178.905
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> NNM gives an ATE of &lt;strong>−210.1 g&lt;/strong> (95% CI: [−267.5, −152.6], z = −7.16) and an ATT of &lt;strong>−238.5 g&lt;/strong>. The ATE is the smallest in absolute value of any estimator we have run, and the confidence interval is the widest &amp;mdash; both are typical features of matching estimators, which trade some precision for the freedom from parametric assumptions. The Stata output also reveals that one observation needed up to 16 matches: this happens when several observations are tied at the same Mahalanobis distance, which is normal when the matching set includes discrete variables. Notice also that NNM is the only method so far where ATT (−238.5 g) is &lt;strong>larger in magnitude&lt;/strong> than ATE (−210.1 g). This is a real feature of matching, not a bug: the actual smokers in this sample occupy a region of covariate space where the matched comparison estimates a larger-magnitude effect. We will return to this point in §13.&lt;/p>
&lt;h2 id="12-method-6-----propensity-score-matching-psm">12. Method 6 &amp;mdash; Propensity-Score Matching (PSM)&lt;/h2>
&lt;p>&lt;strong>Purpose.&lt;/strong> PSM combines the matching idea with the propensity score. Instead of matching on a multidimensional Mahalanobis distance, it collapses all the covariates into a single number &amp;mdash; the estimated propensity &amp;mdash; and matches on that. The intuition is Rosenbaum and Rubin&amp;rsquo;s foundational result: matching on the scalar propensity score is sufficient to balance every covariate that went into estimating it.&lt;/p>
&lt;p>The figure below illustrates the matching idea on a small subsample of 100 mothers, using the propensity scores we estimated in §9.&lt;/p>
&lt;p>&lt;img src="stata_matching_psm_logic.png" alt="Annotated scatter of smoking status against propensity score. An arrow indicates that each smoker is matched to nearby non-smokers in propensity-score space.">&lt;/p>
&lt;p>&lt;strong>Read the figure.&lt;/strong> Each circle is one mother, plotted at her estimated propensity (x-axis) against her actual smoking status (y-axis: 0 for non-smoker, 1 for smoker). PSM matches each smoker (a warm-orange circle at y=1) to the non-smoker(s) (steel-blue circles at y=0) whose estimated propensity is closest. The arrow walks you through one match. After matching, each pair shares (approximately) the same propensity score, which by the Rosenbaum-Rubin theorem means they share the same &lt;em>distribution&lt;/em> of every covariate that entered the propensity model. We can then compare their outcomes apples-to-apples.&lt;/p>
&lt;pre>&lt;code class="language-mermaid">flowchart LR
S[&amp;quot;Smoker&amp;lt;br/&amp;gt;(D=1)&amp;quot;] --&amp;gt; P[&amp;quot;Estimate&amp;lt;br/&amp;gt;e(X) for everyone&amp;quot;]
P --&amp;gt; N[&amp;quot;Find non-smoker&amp;lt;br/&amp;gt;with closest e(X)&amp;quot;]
N --&amp;gt; C[&amp;quot;Compare&amp;lt;br/&amp;gt;outcomes&amp;quot;]
C --&amp;gt; A[&amp;quot;Average&amp;lt;br/&amp;gt;across all&amp;lt;br/&amp;gt;smokers&amp;quot;]
style S fill:#d97757,stroke:#141413,color:#fff
style P fill:#6a9bcc,stroke:#141413,color:#fff
style N fill:#6a9bcc,stroke:#141413,color:#fff
style C fill:#00d4c8,stroke:#141413,color:#141413
style A fill:#141413,stroke:#141413,color:#fff
linkStyle 0,1,2,3 stroke:#141413,stroke-width:1.5px
&lt;/code>&lt;/pre>
&lt;p>The diagram restates the four steps. PSM is conceptually one of the simplest matching methods because the matching distance is one-dimensional: just the absolute difference in propensity scores.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects psmatch (bweight) (mbsmoke mmarried mage fage medu prenatal1), nolog
estimates store te_psmatch
teffects psmatch (bweight) (mbsmoke mmarried mage fage medu prenatal1), atet nolog
estimates store te_psmatch_att
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Estimator : propensity-score matching Matches: requested = 1
Treatment model: logit max = 16
ATE | -229.4492 25.88746 -8.86 0.000 -280.1877 -178.7107
ATET | -224.5927 30.55147 -7.35 0.000 -284.4725 -164.7129
&lt;/code>&lt;/pre>
&lt;p>&lt;strong>Interpretation.&lt;/strong> PSM gives an ATE of &lt;strong>−229.4 g&lt;/strong> (95% CI: [−280.2, −178.7], z = −8.86) and an ATT of &lt;strong>−224.6 g&lt;/strong>. These numbers sit comfortably inside the cluster formed by IPW (−230.9 g), IPWRA (−231.9 g), and AIPW (−232.5 g). Five different methods that take very different routes through the data are now agreeing on roughly &lt;strong>−230 grams&lt;/strong>, with confidence intervals that all comfortably exclude the naive estimate of −275 g. This convergence is the strongest evidence we have that the &lt;strong>−230 g neighborhood&lt;/strong> is not an artifact of any one model&amp;rsquo;s specification.&lt;/p>
&lt;p>The standard diagnostic for PSM is the &lt;strong>overlap plot&lt;/strong> generated by &lt;code>teffects overlap&lt;/code>, shown below. It plots the densities of the estimated propensity score separately for treated and control units after matching.&lt;/p>
&lt;pre>&lt;code class="language-stata">teffects psmatch (bweight) (mbsmoke mmarried mage fage medu prenatal1), nolog
teffects overlap
graph export &amp;quot;stata_matching_overlap.png&amp;quot;, replace width(2400)
&lt;/code>&lt;/pre>
&lt;p>&lt;img src="stata_matching_overlap.png" alt="Overlap plot from teffects overlap after PSM, showing kernel densities of the estimated propensity score for smokers and non-smokers. Both densities span most of the unit interval, supporting the overlap assumption.">&lt;/p>
&lt;p>&lt;strong>Interpretation.&lt;/strong> Both density curves span most of the open unit interval (0, 1). There are no large regions where one group is essentially absent, which is the visual signature of a satisfied overlap assumption. If the smokers' density had collapsed to a small region near 1 (or non-smokers' density had collapsed near 0), we would have a problem &amp;mdash; the propensity-weighted comparisons would be dominated by a handful of extreme observations. Here, the assumption is plausible, and the comparisons are well-supported across the entire (0,1) interval.&lt;/p>
&lt;h2 id="13-comparing-all-six-estimators">13. Comparing all six estimators&lt;/h2>
&lt;p>The most useful single output from this whole exercise is a side-by-side comparison of the seven specifications. The forest plot below was assembled by collecting each estimator&amp;rsquo;s stored ATE and 95% CI into a small dataset and plotting them with &lt;code>twoway&lt;/code>.&lt;/p>
&lt;p>&lt;img src="stata_matching_forest_plot.png" alt="Forest plot of ATE estimates with 95% confidence intervals across seven specifications: naive baseline plus six adjusted estimators. The naive estimate is most negative; the six adjusted estimators cluster around -230 grams, with NNM the slight outlier at -210 grams.">&lt;/p>
&lt;p>&lt;strong>Interpretation.&lt;/strong> Reading top to bottom: the naive baseline (−275 g) is the most negative estimate, with a 95% CI of [−316.8, −233.7] that lies entirely below every adjusted estimator&amp;rsquo;s point estimate except RA (which is right at its upper bound). The six adjusted estimators land in two groups: a tight cluster of five (RA, IPW, IPWRA, AIPW, PSM) between −229 and −240 g, and NNM as a slight outlier at −210 g with a wider CI. &lt;strong>The convergence among the five is the headline.&lt;/strong> They use different functional forms, different covariate sets, and different identification arguments, and they all return a number within ±10 g of each other. NNM&amp;rsquo;s wider CI and slightly smaller magnitude reflect its non-parametric nature (it is doing more work with less help from a model) but its CI overlaps every other estimator&amp;rsquo;s, so the disagreement is well within sampling variation.&lt;/p>
&lt;p>The numbers underlying the plot:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>#&lt;/th>
&lt;th>Estimator&lt;/th>
&lt;th style="text-align:right">ATE (grams)&lt;/th>
&lt;th>95% CI&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>0&lt;/td>
&lt;td>Naive (unadjusted)&lt;/td>
&lt;td style="text-align:right">−275.3&lt;/td>
&lt;td>[−316.8, −233.7]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>Regression Adjustment (RA)&lt;/td>
&lt;td style="text-align:right">−239.6&lt;/td>
&lt;td>[−286.3, −192.9]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>Inverse-Probability Weighting (IPW)&lt;/td>
&lt;td style="text-align:right">−230.9&lt;/td>
&lt;td>[−278.6, −183.3]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3&lt;/td>
&lt;td>IPWRA (doubly robust)&lt;/td>
&lt;td style="text-align:right">−231.9&lt;/td>
&lt;td>[−281.2, −182.6]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4&lt;/td>
&lt;td>AIPW (efficient doubly robust)&lt;/td>
&lt;td style="text-align:right">−232.5&lt;/td>
&lt;td>[−281.1, −183.8]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5&lt;/td>
&lt;td>Nearest-Neighbor Matching (NNM)&lt;/td>
&lt;td style="text-align:right">−210.1&lt;/td>
&lt;td>[−267.5, −152.6]&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>6&lt;/td>
&lt;td>Propensity-Score Matching (PSM)&lt;/td>
&lt;td style="text-align:right">−229.4&lt;/td>
&lt;td>[−280.2, −178.7]&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>And the corresponding ATT estimates, where they are reported:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>#&lt;/th>
&lt;th>Estimator&lt;/th>
&lt;th style="text-align:right">ATT (grams)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>1&lt;/td>
&lt;td>RA&lt;/td>
&lt;td style="text-align:right">−223.3&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>2&lt;/td>
&lt;td>IPW&lt;/td>
&lt;td style="text-align:right">−219.6&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>3&lt;/td>
&lt;td>IPWRA&lt;/td>
&lt;td style="text-align:right">−220.6&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>4&lt;/td>
&lt;td>AIPW&lt;/td>
&lt;td style="text-align:right">not reported in Stata&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>5&lt;/td>
&lt;td>NNM&lt;/td>
&lt;td style="text-align:right">−238.5&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>6&lt;/td>
&lt;td>PSM&lt;/td>
&lt;td style="text-align:right">−224.6&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;strong>A word on the ATT vs. ATE divergence.&lt;/strong> For RA, IPW, IPWRA, and PSM, the ATT is slightly closer to zero than the ATE. The interpretation is that smoking has a slightly less harmful effect on the babies of the women who actually smoked than it would have on a randomly selected mother. NNM reverses this pattern (its ATT of −238.5 g is &lt;em>larger in magnitude&lt;/em> than its ATE of −210.1 g). This is interpretable: NNM is making the matched comparison around the &lt;em>treated&lt;/em> mothers, which means it weights the data in a way that emphasizes the covariate region where actual smokers live &amp;mdash; a region in which smoking happens to do more damage. Whether you should report ATE or ATT depends on the policy question. ATE answers &amp;ldquo;what would happen to a randomly chosen pregnancy if she smoked?&amp;rdquo; ATT answers &amp;ldquo;what is happening to the babies of women who currently smoke?&amp;rdquo; These are different questions with different policy implications, and neither one is more &amp;ldquo;correct&amp;rdquo; in the abstract.&lt;/p>
&lt;h2 id="14-summary-and-key-takeaways">14. Summary and key takeaways&lt;/h2>
&lt;p>After running seven specifications on the same dataset, here is what we know.&lt;/p>
&lt;p>&lt;strong>Eight methodological lessons.&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>The naive comparison is biased upward (toward larger magnitude) by about 35 to 65 grams.&lt;/strong> Adjusting for observable covariates moves the answer from −275 g to roughly −230 g, a 13% to 24% reduction in the apparent harm.&lt;/li>
&lt;li>&lt;strong>Five of six adjusted estimators agree within 10 grams.&lt;/strong> RA, IPW, IPWRA, AIPW, and PSM cluster between −229 and −240 g. When estimators with very different functional forms agree this closely, the maintained identification assumption (conditional independence) is probably approximately correct on this sample.&lt;/li>
&lt;li>&lt;strong>Doubly robust is essentially free.&lt;/strong> IPWRA and AIPW differ from each other by less than a gram and from plain IPW by less than two grams. The protection they offer against outcome- or treatment-model misspecification costs essentially nothing in this dataset.&lt;/li>
&lt;li>&lt;strong>&lt;code>teffects&lt;/code> is not a black box.&lt;/strong> The manual recreation of RA recovered −239.64 g exactly, and the manual recreation of IPW gave −232.13 g (within 1.2 g of the canned probit version). Every method in this tutorial is, in the end, a few &lt;code>regress&lt;/code>/&lt;code>logistic&lt;/code> calls and a weighted average.&lt;/li>
&lt;li>&lt;strong>Propensity scores have predictive power but leave room for matching.&lt;/strong> The logistic propensity model has pseudo-R² of 7.8% and likelihood-ratio chi-square of 346. Weak enough to ensure overlap; strong enough that re-weighting makes a difference.&lt;/li>
&lt;li>&lt;strong>NNM trades precision for flexibility.&lt;/strong> Mahalanobis matching gives a wider CI (−267 to −152 g) than the model-based methods. The point estimate (−210 g) is closer to zero than the cluster, but the CI overlaps every other estimator&amp;rsquo;s.&lt;/li>
&lt;li>&lt;strong>ATT and ATE diverge for matching methods.&lt;/strong> Five estimators give ATTs slightly closer to zero than their ATE. NNM reverses this pattern. The right question to ask about your application is which of the two estimands matches your policy question.&lt;/li>
&lt;li>&lt;strong>Sample design matters.&lt;/strong> With ~864 smokers in a sample of 4,642, propensity scores spanning most of (0, 1), and &lt;code>teffects nnmatch&lt;/code> finding at most 16 matches per treated unit, this dataset is an unusually well-behaved teaching example. Real-world applications often have much sparser overlap, and you will know it when &lt;code>teffects overlap&lt;/code> looks ragged.&lt;/li>
&lt;/ol>
&lt;h2 id="15-limitations-and-next-steps">15. Limitations and next steps&lt;/h2>
&lt;p>Every estimator above relies on three assumptions: conditional independence, overlap, and SUTVA. Conditional independence is the most fragile. If something we did not measure &amp;mdash; say, genetic predispositions, prenatal nutrition, household income, or chronic stress &amp;mdash; drives both the smoking decision and birth weight directly, every one of the six estimators is biased in the same direction. &lt;strong>None of the six methods can rescue an analyst from missing confounders.&lt;/strong> That is what makes the conditional-independence assumption so important to scrutinize before publishing a number from this kind of analysis.&lt;/p>
&lt;p>Three classes of follow-up are worth knowing about.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Sensitivity analysis&lt;/strong> &amp;mdash; methods like Rosenbaum bounds, the E-value, or &lt;code>causalsens&lt;/code> quantify &lt;em>how strong&lt;/em> an unobserved confounder would have to be to overturn the result. A sensible workflow is: run the six estimators above, then ask &amp;ldquo;how robust is the −230 g number to omitted variables?&amp;rdquo;&lt;/li>
&lt;li>&lt;strong>Instrumental variables&lt;/strong> &amp;mdash; when a credible instrument exists (say, regional cigarette taxes or anti-smoking advertising shocks), 2SLS or LATE estimators can identify the effect of smoking &lt;em>for compliers&lt;/em> even under unobserved confounding.&lt;/li>
&lt;li>&lt;strong>Machine-learning-based estimators&lt;/strong> &amp;mdash; methods like Double/Debiased Machine Learning (DML), causal forests, and meta-learners replace the parametric outcome and treatment models above with flexible learners (random forest, gradient boosting), which is especially valuable when there are many covariates or when the outcome is non-linear in &lt;code>X&lt;/code>. They are doubly robust like AIPW but make weaker functional-form assumptions.&lt;/li>
&lt;/ol>
&lt;p>For a Python walkthrough of DML on a similar style of problem, see &lt;code>python_doubleml&lt;/code>. For a starter on the broader causal-inference workflow with &lt;code>dowhy&lt;/code>, see &lt;code>python_dowhy&lt;/code>.&lt;/p>
&lt;h2 id="16-exercises">16. Exercises&lt;/h2>
&lt;p>Six exercises to consolidate what you&amp;rsquo;ve just read. Each can be answered in 5–15 lines of Stata code.&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Different covariate set.&lt;/strong> Re-estimate RA, IPW, and AIPW dropping &lt;code>prenatal1&lt;/code> from the outcome model and &lt;code>medu&lt;/code> from the treatment model. How much do the estimates change? What does this tell you about which covariates carry the most weight?&lt;/li>
&lt;li>&lt;strong>Logit instead of probit.&lt;/strong> Re-estimate IPW and IPWRA using &lt;code>logit&lt;/code> instead of &lt;code>probit&lt;/code> for the treatment model. Compare the estimates and standard errors. Which one is &amp;ldquo;correct&amp;rdquo;?&lt;/li>
&lt;li>&lt;strong>More matches.&lt;/strong> Re-estimate NNM and PSM with &lt;code>nneighbor(3)&lt;/code> and &lt;code>nneighbor(5)&lt;/code>. Watch what happens to the standard errors. Why?&lt;/li>
&lt;li>&lt;strong>The full ATT comparison.&lt;/strong> Build a forest plot of the ATT (instead of the ATE) for the five methods that report it. Where do they disagree? What does the disagreement say about which mothers drive the result?&lt;/li>
&lt;li>&lt;strong>Robustness with pscore-trimming.&lt;/strong> Drop observations whose propensity score is below 0.05 or above 0.95, then re-run all six methods. How sensitive is the conclusion to extreme observations?&lt;/li>
&lt;li>&lt;strong>Sensitivity analysis.&lt;/strong> Install &lt;code>regsensitivity&lt;/code> (&lt;code>ssc install regsensitivity&lt;/code>) and re-estimate the RA model with the package&amp;rsquo;s &lt;code>breakdown&lt;/code> function to find the magnitude of unobserved confounding that would erase the result.&lt;/li>
&lt;/ol>
&lt;h2 id="17-references">17. References&lt;/h2>
&lt;ol>
&lt;li>&lt;a href="https://doi.org/10.1016/j.jeconom.2009.09.023" target="_blank" rel="noopener">Cattaneo, M. D. (2010). Efficient semiparametric estimation of multi-valued treatment effects under ignorability. &lt;em>Journal of Econometrics&lt;/em>, 155(2), 138–154.&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://doi.org/10.1017/CBO9781139025751" target="_blank" rel="noopener">Imbens, G. W. and Rubin, D. B. (2015). &lt;em>Causal Inference for Statistics, Social, and Biomedical Sciences&lt;/em>. Cambridge University Press.&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://mitpress.mit.edu/9780262232586/econometric-analysis-of-cross-section-and-panel-data/" target="_blank" rel="noopener">Wooldridge, J. M. (2010). &lt;em>Econometric Analysis of Cross Section and Panel Data&lt;/em>, 2nd ed. MIT Press.&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://doi.org/10.1093/biomet/70.1.41" target="_blank" rel="noopener">Rosenbaum, P. R. and Rubin, D. B. (1983). The central role of the propensity score in observational studies for causal effects. &lt;em>Biometrika&lt;/em>, 70(1), 41–55.&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://doi.org/10.1111/j.1468-0262.2006.00655.x" target="_blank" rel="noopener">Abadie, A. and Imbens, G. W. (2006). Large sample properties of matching estimators for average treatment effects. &lt;em>Econometrica&lt;/em>, 74(1), 235–267.&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://www.stata.com/manuals/te.pdf" target="_blank" rel="noopener">Stata Corp. (2023). &lt;em>Stata Treatment-Effects Reference Manual&lt;/em>: &lt;code>teffects ra&lt;/code>, &lt;code>teffects ipw&lt;/code>, &lt;code>teffects ipwra&lt;/code>, &lt;code>teffects aipw&lt;/code>, &lt;code>teffects nnmatch&lt;/code>, &lt;code>teffects psmatch&lt;/code>.&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/quarcs-lab/data-open/raw/master/ametrics/cattaneo2.dta" target="_blank" rel="noopener">Cattaneo (2010) data on maternal smoking and birth weight (&lt;code>cattaneo2.dta&lt;/code>)&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://youtu.be/mvEUuEd4nCY" target="_blank" rel="noopener">Carlos Mendez &amp;mdash; Video tutorial: Treatment-effects estimators in Stata&lt;/a>&lt;/li>
&lt;li>&lt;a href="analysis.do">Carlos Mendez &amp;mdash; Companion Stata &lt;code>do&lt;/code>-file (&lt;code>analysis.do&lt;/code>)&lt;/a>&lt;/li>
&lt;/ol>
&lt;hr>
&lt;p>&lt;em>If you spot an error or have a suggestion, please open an issue on the &lt;a href="https://github.com/quarcs-lab/starter-academic-v501" target="_blank" rel="noopener">website&amp;rsquo;s GitHub repository&lt;/a> or &lt;a href="mailto:carlos.a.mendez@gmail.com">email me directly&lt;/a>. The companion &lt;code>analysis.do&lt;/code> is designed to run end-to-end in under 30 seconds on a 2020-era laptop with Stata 17 or later.&lt;/em>&lt;/p></description></item></channel></rss>