<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cdid user guide | David Benatia</title><link>https://www.davidbenatia.com/tools/cdid/stata/</link><atom:link href="https://www.davidbenatia.com/tools/cdid/stata/index.xml" rel="self" type="application/rss+xml"/><description>cdid user guide</description><generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Mon, 16 Nov 2026 00:00:00 +0000</lastBuildDate><image><url>https://www.davidbenatia.com/media/icon_huf51d053dcee75059daeadc3a21b01f3b_32112_512x512_fill_lanczos_center_3.png</url><title>cdid user guide</title><link>https://www.davidbenatia.com/tools/cdid/stata/</link></image><item><title>Add PT-all restrictions</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/pt-all-comparison/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/pt-all-comparison/</guid><description>&lt;p>&lt;code>ptassumption(post)&lt;/code> leaves the differential trends before the reference period unrestricted. &lt;code>ptassumption(all) ptstart(#)&lt;/code> keeps PT-post and each cohort&amp;rsquo;s reference period and adds the restriction that the differential trends are zero on every step from the common calendar date &lt;code>ptstart()&lt;/code> onward. &lt;code>baseperiod()&lt;/code> separately controls how pretreatment cells are reported.&lt;/p>
&lt;p>This page compares the two assumptions in a design where PT-all is false. When parallel trends hold in all periods, both sets of restrictions are valid. PT-all can add information or identification, but no finite-sample precision improvement is guaranteed.&lt;/p>
&lt;h2 id="a-pre-reference-pulse">A pre-reference pulse&lt;/h2>
&lt;p>Take cohorts first treated at 3 and 5, no anticipation, and reference dates 2 and 4. Add a common $+0.5$ untreated pulse to the treated cohorts at date 1 only. All outcomes at dates 2 onward, all post-treatment causal effects, and PT-post remain unchanged. The differential on step $1\to2$ changes by $-0.5$, so PT-all from date 1 imposes a false restriction. Under PT-post, the earlier differential trends remain free parameters and cancel in the valid comparisons through earlier dates.&lt;/p>
&lt;p>These statements concern population moments. They do not imply that all finite-sample post estimates are exactly unchanged, that a Wald test must reject, or that every PT-all estimate moves in one direction. Shared adjustment models, the estimated covariance of the comparisons and sampling variation all matter.&lt;/p>
&lt;h2 id="estimation-with-and-without-the-pulse">Estimation with and without the pulse&lt;/h2>
&lt;p>Run Sections 0 and 1 of the hands-on do-file first. Sections 3a and 3c estimate the model under PT-post and PT-all; the following two calls add the pulse:&lt;/p>
&lt;pre>&lt;code class="language-stata">generate double y_pulse = y + 0.5 * (first_treat &amp;gt; 0 &amp;amp; period == 1) if !missing(y)
cdid y_pulse x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) ptassumption(post) bstrap(0) cband(0)
cdid y_pulse x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) ptassumption(all) ptstart(1) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;p>The simulated observation process is not accounted for by these specifications, which use &lt;code>selection(none)&lt;/code>. The pulse leaves the observed outcomes in place; the example shows how sensitive the estimates are to the added restrictions and gives no evidence of consistency or coverage for this sample. Choose the period over which parallel trends are assumed from substantive knowledge, before looking at the results.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 14 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/">Parallel trends&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/">GMM weighting and covariance regularization&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Choose an observation model for missing outcomes</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/observation-models/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/observation-models/</guid><description>&lt;p>When outcome observation depends on covariates that also shift outcome changes or treatment effects, &lt;code>selection(conditional_mtar)&lt;/code> with &lt;code>selmethod(ipw)&lt;/code> (or &lt;code>selmethod(dr)&lt;/code>) estimates the probability $q_c(W_i)$ that a unit in cohort $k$ is observed at both endpoints of date pair $e = (s, t)$ (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>).&lt;/p>
&lt;p>This page compares the two observation models and the three pooling restrictions on their slopes. The examples below are Section 4 of the hands-on do-file.&lt;/p>
&lt;h2 id="1-two-observation-model-families-selmodel">1. Two observation model families (&lt;code>selmodel()&lt;/code>)&lt;/h2>
&lt;p>For each needed cohort $k$ and ordered date pair $e = (s, t)$, let $R_{i,t} \in {0, 1}$ indicate whether outcome $Y_{i,t}$ is observed at date $t$, so pair observation is the product $S_{i,e} = R_{i,s} R_{i,t} \in {0, 1}$.&lt;/p>
&lt;h3 id="direct-pair-logit-selmodelpair_logit-default">Direct pair logit (&lt;code>selmodel(pair_logit)&lt;/code>, default)&lt;/h3>
&lt;p>&lt;code>selmodel(pair_logit)&lt;/code> directly models the pair indicator $S_{i,e} = R_{i,s} R_{i,t}$ using a logistic link:&lt;/p>
&lt;p>$$q_{k,e}(W_i) = P(S_{i,e} = 1 \mid G_i = k, W_i) = \Lambda!\left(\alpha_{k,e} + z_Q(W_i)'\gamma_r\right)$$&lt;/p>
&lt;p>where $\Lambda(u) = (1 + e^{-u})^{-1}$, $\alpha_{k,e}$ is a cell-specific intercept for cohort $k$ and pair $e$ (unless &lt;code>selnoconstant&lt;/code> or &lt;code>selzero&lt;/code> is specified), and $\gamma_r$ is the slope vector for pooling group $r$.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Advantage:&lt;/strong> Does not require $R_{i,s}$ and $R_{i,t}$ to be conditionally independent given $(G_i = k, W_i)$; it models their joint pair indicator directly.&lt;/li>
&lt;li>&lt;strong>When it is exact vs approximate:&lt;/strong> If single-date observation $R_{i,t}$ follows independent date logits $\Lambda(\theta_{k,t} + W_i'\delta)$, their product $\Lambda(\theta_{k,s} + W_i'\delta),\Lambda(\theta_{k,t} + W_i'\delta)$ is not itself a single logistic function when $W_i$ is continuous (though with a single binary covariate and &lt;code>selpooling(separate)&lt;/code>, a saturated two-parameter pair logit still represents every two-point probability exactly).&lt;/li>
&lt;/ul>
&lt;h3 id="product-of-date-logits-selmodelindependent_period_logit">Product of date logits (&lt;code>selmodel(independent_period_logit)&lt;/code>)&lt;/h3>
&lt;p>&lt;code>selmodel(independent_period_logit)&lt;/code> fits a binary logit for single-date observation $R_{i,d}$ at each needed cohort $k$ and date $d \in {s, t}$:&lt;/p>
&lt;p>$$r_{k,d}(W_i) = P(R_{i,d} = 1 \mid G_i = k, W_i) = \Lambda!\left(\alpha_{k,d} + z_Q(W_i)'\gamma_r\right)$$&lt;/p>
&lt;p>and constructs the pair observation probability as the product of the two endpoint probabilities:&lt;/p>
&lt;p>$$q_{k,(s,t)}(W_i) = r_{k,s}(W_i) , r_{k,t}(W_i)$$&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Advantage:&lt;/strong> Directly matches wave-by-wave independent response designs and fits one logit per needed cohort-date $(k, d)$ rather than one per cohort-pair used.&lt;/li>
&lt;li>&lt;strong>Requirement:&lt;/strong> Requires that $R_{i,s}$ and $R_{i,t}$ are conditionally independent given $(G_i = k, W_i)$ on the fitting universe and requires &lt;code>seluniverse(F)&lt;/code>. A mean-outcome restriction alone does not justify replacing the joint response probability by a product.&lt;/li>
&lt;/ul>
&lt;h2 id="2-three-slope-pooling-choices-selpooling">2. Three slope-pooling choices (&lt;code>selpooling()&lt;/code>)&lt;/h2>
&lt;p>Across both &lt;code>pair_logit&lt;/code> and &lt;code>independent_period_logit&lt;/code>, every cell (each cohort-pair $(k, e)$ or cohort-date $(k, d)$) keeps its &lt;strong>own local intercept&lt;/strong> whenever an intercept is included. The option &lt;code>selpooling()&lt;/code> governs how the &lt;strong>covariate slope vector&lt;/strong> $\gamma_r$ is shared across cells:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;code>selpooling()&lt;/code>&lt;/th>
&lt;th>Slope restriction on $q$&lt;/th>
&lt;th>Fit structure&lt;/th>
&lt;th>When appropriate&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>separate&lt;/code> (default)&lt;/td>
&lt;td>Separate slope vector $\gamma_{k,e}$ per cohort-pair (or $\gamma_{k,d}$ per cohort-date)&lt;/td>
&lt;td>One fit per cell used&lt;/td>
&lt;td>Covariate effects on observation can vary across cohorts and across calendar dates/pairs.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>within_cohort&lt;/code>&lt;/td>
&lt;td>One shared slope vector $\gamma_k$ per cohort across all of its pairs or dates (with separate intercepts per pair/date)&lt;/td>
&lt;td>One joint fit per cohort&lt;/td>
&lt;td>Covariate effects on observation are stable over time within each cohort, but may differ between cohorts.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>across_cohorts&lt;/code>&lt;/td>
&lt;td>One global slope vector $\gamma$ shared across all cohorts and all pairs or dates (with separate intercepts per cell)&lt;/td>
&lt;td>One joint fit across all cells used&lt;/td>
&lt;td>Covariates shift log-odds of observation identically across all cohorts and periods, while baseline response rates shift via cell intercepts.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>[!WARNING]
&lt;strong>Slope pooling does not remove cell intercepts or cure complete separation:&lt;/strong> Because &lt;code>within_cohort&lt;/code> and &lt;code>across_cohorts&lt;/code> keep a free intercept $\alpha_c$ for every cell $c$, a cell in which 100% or 0% of units are observed still has no finite maximum likelihood estimate of its intercept, and estimation stops with &lt;code>r(498)&lt;/code>. &lt;code>cdid&lt;/code> does not switch to another pooling (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/troubleshooting/">Diagnose errors and unavailable results&lt;/a>).&lt;/p>
&lt;/blockquote>
&lt;h2 id="3-examples-in-stata">3. Examples in Stata&lt;/h2>
&lt;p>Section 4a compares the two models with a binary covariate. Section 4b uses separate covariates for the outcome and observation models and the unit table of the study population:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y i.x_bin, ivar(id) time(period) gvar(first_treat) ///
selection(conditional_mtar) selmodel(pair_logit) selpooling(separate) ///
biters($CDID_DEMO_BITERS)
cdid y i.x_bin, ivar(id) time(period) gvar(first_treat) ///
selection(conditional_mtar) selmodel(independent_period_logit) selpooling(separate) ///
biters($CDID_DEMO_BITERS)
* 4b. Separate outcome covariates `covars()` and selection covariates `selcovars()`
* with the unit table `frame(cdid_pop)` of the study population
cdid y, ivar(id) time(period) gvar(first_treat) ///
covars(i.x_bin c.x_cont) ///
selection(conditional_mtar) selmodel(pair_logit) selpooling(separate) ///
selcovars(i.x_bin c.x_cont c.z_sel) ///
frame(cdid_pop) frameivar(id) framegvar(first_treat) ///
framecovars(x_bin x_cont) frameselcovars(x_bin x_cont z_sel) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;p>The first two models omit &lt;code>z_sel&lt;/code> on purpose; the simulated data also include units observed once or never. That these models can be estimated says nothing about whether they are correct or give the same estimates. Section 4c pools the pair logits within and across cohorts. Pooling keeps each cell intercept, so a perfectly separated cell still has no finite estimate.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 11 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/sampling-information/">Sampling information for the observation model&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/change-imputation/">Impute actual changes for missing outcomes&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Choose IPW, OR or DR in an incomplete panel</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/treatment-choice/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/treatment-choice/</guid><description>&lt;p>When baseline covariates $X_i$ influence both which cohort a unit joins and how untreated outcomes evolve over time, unadjusted difference-in-differences comparisons are confounded by covariate differences across cohorts. In &lt;code>mode(chained)&lt;/code>, &lt;code>cdid&lt;/code> provides three treatment-adjustment methods: inverse probability weighting (&lt;code>method(ipw)&lt;/code>), regression of the controls' outcome changes (&lt;code>method(reg)&lt;/code>), and doubly robust estimation (&lt;code>method(dr)&lt;/code>), with &lt;code>outcomepooling(separate|pooled)&lt;/code> governing slope sharing across comparison blocks for &lt;code>method(reg|dr)&lt;/code> (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/">Treatment adjustment&lt;/a>).&lt;/p>
&lt;p>The model of cohort membership below is a theoretical example; it does not describe how the simulated data of the hands-on do-file assign cohorts.&lt;/p>
&lt;h2 id="question">Question&lt;/h2>
&lt;p>Holding the incomplete panel, the study-population frame &lt;code>frame(cdid_pop)&lt;/code>, the covariates &lt;code>x_bin x_cont&lt;/code>, &lt;code>ptassumption(post)&lt;/code>, &lt;code>baseperiod(varying)&lt;/code>, and &lt;code>selection(none)&lt;/code> fixed, how do &lt;code>method(ipw)&lt;/code>, &lt;code>method(reg)&lt;/code>, and &lt;code>method(dr)&lt;/code> construct their nuisance fits, and how do their cell and aggregate estimates compare?&lt;/p>
&lt;h2 id="model-algebra-for-the-two-nuisance-models">Model algebra for the two nuisance models&lt;/h2>
&lt;h3 id="1-control-outcome-change-regression-m_bx-methodreg-and-methoddr">1. Control outcome-change regression $m_b(X)$ (&lt;code>method(reg)&lt;/code> and &lt;code>method(dr)&lt;/code>)&lt;/h3>
&lt;p>Suppose untreated potential outcomes follow&lt;/p>
&lt;p>$$Y_{i,t}(0) = \alpha_i + \delta_t + t, X_i'\beta_0 + \varepsilon_{i,t}, \qquad E[\varepsilon_{i,t} \mid G_i, X_i, S_i] = 0$$&lt;/p>
&lt;p>Across any ordered calendar pair $e = (s, t)$ on a consecutive calendar $t \in {1, \dots, T}$ where $L(e) = i_t - i_s = t - s$, the conditional mean untreated change is:&lt;/p>
&lt;p>$$E[Y_{i,t}(0) - Y_{i,s}(0) \mid X_i, G_i \in K] = (\delta_t - \delta_s) + L(e), X_i'\beta_0$$&lt;/p>
&lt;p>Under default &lt;code>outcomepooling(separate)&lt;/code>, &lt;code>cdid&lt;/code> fits a separate regression $m_b(X_i) = \alpha_b + L(e), z(X_i)'\beta_b$ on each comparison block $b = (e, K)$, which accommodates both a constant per-step slope $\beta_b = \beta_0$ and block-varying covariate trend slopes $\beta_b$. Under &lt;code>outcomepooling(pooled)&lt;/code>, &lt;code>cdid&lt;/code> imposes the constant-per-step restriction across all blocks simultaneously:&lt;/p>
&lt;p>$$m_b(X_i) = \alpha_b + L(e), z(X_i)'\beta$$&lt;/p>
&lt;p>with local block intercept $\alpha_b = \delta_t - \delta_s$ for each comparison block $b = (e, K)$ and shared slope vector $\beta = \beta_0$.&lt;/p>
&lt;h3 id="2-risk-set-treatment-propensity-logit-p_gkx-methodipw-and-methoddr">2. Risk-set treatment propensity logit $p_{g,K}(X)$ (&lt;code>method(ipw)&lt;/code> and &lt;code>method(dr)&lt;/code>)&lt;/h3>
&lt;p>Suppose cohort assignment across $G_i \in {0, 3, 5}$ follows a multinomial logit with linear predictors $\eta_g(X_i) = a_g + X_i'\gamma_g$ relative to $G_i = 0$ ($\eta_0(X_i) = 0$):&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Under &lt;code>controlgroup(nevertreated)&lt;/code>:&lt;/strong> Every comparison for target cohort $g \in {3, 5}$ uses the single control cohort $K = {0}$. Conditional on belonging to the risk set $G_i \in {g, 0}$, the log-odds of belonging to cohort $g$ versus control $K = {0}$ are:
$$\log\frac{P(G_i = g \mid X_i,, G_i \in {g, 0})}{P(G_i = 0 \mid X_i,, G_i \in {g, 0})} = a_g + X_i'\gamma_g$$
Because this conditional log-odds is exactly linear in $X_i$, the binary logit $p_{g,{0}}(X_i)$ fitted by &lt;code>cdid&lt;/code> is exact for every cohort $g$.&lt;/li>
&lt;li>&lt;strong>Under &lt;code>controlgroup(notyettreated)&lt;/code>:&lt;/strong> For cohort $g = 3$ on pairs $e = (s, t)$ with $\max(s, t) \le 4$ (when &lt;code>anticipation(0)&lt;/code>), the control pool is $K = {0, 5}$. Conditional on $G_i \in {3, 0, 5}$, the log-odds of $G_i = 3$ versus $G_i \in {0, 5}$ are:
$$\log\frac{P(G_i = 3 \mid X_i)}{P(G_i = 0 \mid X_i) + P(G_i = 5 \mid X_i)} = a_3 + X_i'\gamma_3 - \log!\left(1 + \exp(a_5 + X_i'\gamma_5)\right)$$
This is strictly linear in $X_i$ when $\gamma_5 = 0$ (or when $X_i$ is binary/saturated), and otherwise is a smooth log-sum-exp function of $X_i$. Under &lt;code>method(dr)&lt;/code>, even if the pooled risk-set logit is only an approximation, consistency is preserved whenever the control outcome regression $m_b(X_i)$ is correctly specified.&lt;/li>
&lt;/ul>
&lt;h2 id="stata-comparison-and-diagnostics">Stata comparison and diagnostics&lt;/h2>
&lt;p>Run the three estimations of &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/#5-comparing-the-built-in-methods-in-stata">Treatment adjustment&lt;/a>, which are Sections 3a and 3d of the hands-on do-file. After each, &lt;code>cdid_diagnostics, detail&lt;/code> reports the number of treatment models and pooled regressions fitted. These numbers depend on the comparisons available and on the options.&lt;/p>
&lt;p>The multinomial example above gives sufficient conditions for correct models, not finite-sample guarantees. A binary pair logit can be saturated in a binary covariate, while a combined not-yet-treated pool generally has nonlinear log-sum-exp odds. DR is consistent when either the propensity or the outcome model is correct only under valid trend, observation, overlap and regularity conditions.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 8 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/">Treatment adjustment&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Clustered inference, confidence bands, and pretrend tests</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/inference/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/inference/</guid><description>&lt;p>After estimating group-time average treatment effects on an incomplete panel, applied analyses typically need standard errors that account for within-cluster dependence, simultaneous confidence bands across group-time cells or event-study horizons, and diagnostic pretrend tests. &lt;code>cdid&lt;/code> propagates complete $N_F$-row unit influence functions through every output without refitting the underlying models.&lt;/p>
&lt;p>This page explains the standard errors, intervals and bands reported by &lt;code>cdid&lt;/code>, clustering, and the two pretrend tests. Sections 6 through 8 of the hands-on do-file apply them.&lt;/p>
&lt;h2 id="1-pointwise-intervals-versus-simultaneous-bands-across-output-families">1. Pointwise intervals versus simultaneous bands across output families&lt;/h2>
&lt;p>In Stata &lt;code>cdid&lt;/code>, &lt;code>bstrap(#)&lt;/code> (default &lt;code>1&lt;/code>) and &lt;code>cband(#)&lt;/code> (default &lt;code>1&lt;/code>) control standard errors and confidence bands across group-time cells and &lt;code>estat&lt;/code> aggregations:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;code>bstrap()&lt;/code>&lt;/th>
&lt;th>&lt;code>cband()&lt;/code>&lt;/th>
&lt;th>Reported inference for &lt;code>cdid&lt;/code> and &lt;code>estat group|dynamic|calendar&lt;/code>&lt;/th>
&lt;th>Group-time cells of &lt;code>cdid&lt;/code>&lt;/th>
&lt;th>Scalar &lt;code>estat simple&lt;/code> and &lt;code>Overall ATT&lt;/code> summaries&lt;/th>
&lt;th>Separate bins of &lt;code>estat group&lt;/code>, &lt;code>dynamic&lt;/code>, &lt;code>calendar&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>0&lt;/code>&lt;/td>
&lt;td>&lt;code>0&lt;/code>&lt;/td>
&lt;td>&lt;code>analytical&lt;/code>&lt;/td>
&lt;td>Analytical sandwich SEs, pointwise normal CIs&lt;/td>
&lt;td>Analytical sandwich SE, pointwise normal CI&lt;/td>
&lt;td>Analytical sandwich SEs, pointwise normal CIs&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>1&lt;/code>&lt;/td>
&lt;td>&lt;code>0&lt;/code>&lt;/td>
&lt;td>&lt;code>multiplier_bootstrap_se&lt;/code>&lt;/td>
&lt;td>Multiplier IQR SEs, pointwise normal CIs&lt;/td>
&lt;td>Multiplier IQR SE, pointwise normal CI&lt;/td>
&lt;td>Multiplier IQR SEs, pointwise normal CIs&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>1&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code>&lt;/td>
&lt;td>&lt;code>multiplier_bootstrap_cband&lt;/code>&lt;/td>
&lt;td>Multiplier IQR SEs, simultaneous band (&lt;code>e(critical_value)&lt;/code>)&lt;/td>
&lt;td>Multiplier IQR SE (&lt;code>multiplier_bootstrap_se&lt;/code>), pointwise normal CI&lt;/td>
&lt;td>Multiplier IQR SEs, simultaneous band (&lt;code>e(critical_value)&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>0&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code>&lt;/td>
&lt;td>&lt;code>analytical&lt;/code> (on &lt;code>cdid&lt;/code>) / &lt;code>analytical_cband&lt;/code> (on multi-bin &lt;code>estat&lt;/code>)&lt;/td>
&lt;td>Analytical sandwich SEs, pointwise normal CIs (&lt;code>0&lt;/code> draws)&lt;/td>
&lt;td>Analytical sandwich SE, pointwise normal CI (&lt;code>0&lt;/code> draws)&lt;/td>
&lt;td>Analytical sandwich SEs with a multiplier simultaneous critical value &lt;code>e(critical_value)&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Three distinctions matter:&lt;/p>
&lt;ol>
&lt;li>&lt;code>e(se)&lt;/code> holds the reported standard errors, analytical or from the multiplier bootstrap; &lt;code>e(V)&lt;/code> is the analytical covariance. &lt;code>e(ci)&lt;/code> holds the reported intervals or bands, and &lt;code>e(ci_pointwise)&lt;/code> the pointwise intervals when they are available. In ordinary mode, some pointwise intervals can be missing; missing values are not recomputed on export.&lt;/li>
&lt;li>Bands over the bins of an aggregation differ from the interval of the overall estimate, which is always a pointwise normal interval. &lt;code>e(overall_inference_kind)&lt;/code> states the inference used for the overall estimate.&lt;/li>
&lt;li>Each cell fit and aggregation forms its own simultaneous family; separate commands do not establish one global band.&lt;/li>
&lt;/ol>
&lt;h2 id="2-how-the-clustered-multiplier-bootstrap-and-influence-functions-work">2. How the clustered multiplier bootstrap and influence functions work&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>No resampling or refitting:&lt;/strong> &lt;code>cdid&lt;/code> computes an $N_F \times K$ influence-function matrix with one row for every unit in the study population $F$ (&lt;code>N_F = e(N_full)&lt;/code>), including singletons ($B \setminus A$) and unit-table-only units ($F \setminus B$). These influence functions account for the estimation of every model used ($p, m, q, j$), of the observation rates, and (in &lt;code>estat&lt;/code>) of the cohort shares.&lt;/li>
&lt;li>&lt;strong>Clustered row sums and Rademacher draws:&lt;/strong> When &lt;code>cluster(varname)&lt;/code> (and &lt;code>framecluster(name)&lt;/code>) is specified, influence-function rows are summed within each of the $C = \text{e(N_clusters)}$ clusters on $F$. Each of the &lt;code>biters(#)&lt;/code> multiplier bootstrap draws multiplies the $C$ cluster sums (or the $N_F$ unit rows when unclustered) by independent Rademacher signs ($\pm 1$ with probability $0.5$) from Stata&amp;rsquo;s random-number stream (&lt;code>set seed #&lt;/code> reproduces them exactly).&lt;/li>
&lt;li>&lt;strong>Interquartile range (IQR) scale and symmetric bands:&lt;/strong> Multiplier bootstrap standard errors use the bootstrap draw interquartile range divided by the standard normal interquartile range ($\Phi^{-1}(0.75) - \Phi^{-1}(0.25)$), and confidence bands are symmetric: $\hat{\theta}_j \pm c \times \text{SE}_j$.&lt;/li>
&lt;li>&lt;strong>Clustering never changes point estimates:&lt;/strong> Two-step GMM weights (&lt;code>gmmweighting(optimal)&lt;/code>) and Tikhonov regularization (&lt;code>gmmcovariance(tikhonov)&lt;/code>) always use unit-level influence-function covariances on $F$, independently of &lt;code>cluster()&lt;/code>. Adding or removing &lt;code>cluster()&lt;/code> changes standard errors, confidence intervals, and Wald statistics while leaving &lt;code>e(b)&lt;/code> identical.&lt;/li>
&lt;li>&lt;strong>Point estimates only (&lt;code>noinffunc&lt;/code>):&lt;/strong> with &lt;code>noinffunc&lt;/code>, no standard errors, intervals or tests are returned (&lt;code>e(wald_status) == &amp;quot;not_computed&amp;quot;&lt;/code>); the point estimates are unchanged, because the GMM weighting still uses the influence functions. &lt;code>estat&lt;/code> cannot aggregate these results.&lt;/li>
&lt;/ul>
&lt;h2 id="3-unconditional-wald-pretrend-test-vs-standalone-conditional-cdid_pretest">3. Unconditional Wald pretrend test vs standalone conditional &lt;code>cdid_pretest&lt;/code>&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> provides two distinct pretrend tests that test different null hypotheses:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Feature&lt;/th>
&lt;th>Unconditional joint Wald test (&lt;code>cdid&lt;/code>)&lt;/th>
&lt;th>Conditional Cramér-von Mises test (&lt;code>cdid_pretest&lt;/code>)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Command and results&lt;/td>
&lt;td>Computed by &lt;code>cdid&lt;/code> (results in &lt;code>e()&lt;/code>)&lt;/td>
&lt;td>Separate command &lt;code>cdid_pretest&lt;/code> (results in &lt;code>r()&lt;/code>; &lt;code>e()&lt;/code> is unchanged)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Default &lt;code>method()&lt;/code>&lt;/td>
&lt;td>&lt;code>method(dr)&lt;/code> (default of &lt;code>cdid&lt;/code>)&lt;/td>
&lt;td>&lt;code>method(ipw)&lt;/code> (default of &lt;code>cdid_pretest&lt;/code>; pass &lt;code>method(dr)&lt;/code> or &lt;code>method(reg)&lt;/code> to override)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Parallel trends &amp;amp; GMM options&lt;/td>
&lt;td>Uses the &lt;code>ptassumption()&lt;/code> and &lt;code>gmmweighting()&lt;/code> of the &lt;code>cdid&lt;/code> estimation&lt;/td>
&lt;td>Evaluates direct pre-treatment pairs; has &lt;strong>no&lt;/strong> &lt;code>ptassumption()&lt;/code>, &lt;code>ptstart()&lt;/code>, &lt;code>gmmweighting()&lt;/code>, or &lt;code>gmmcovariance()&lt;/code> options&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Null hypothesis&lt;/td>
&lt;td>Jointly tests that all pretreatment cells other than reference cells (&lt;code>role == &amp;quot;pre&amp;quot;&lt;/code>), as defined by &lt;code>baseperiod()&lt;/code>, equal zero &lt;strong>unconditionally&lt;/strong>&lt;/td>
&lt;td>Tests that, for every pretreatment cell other than reference cells, as defined by &lt;code>baseperiod()&lt;/code>, the &lt;strong>conditional mean comparison&lt;/strong> given $X$ at the earlier date equals zero over the distribution of the units of $F$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Stored results&lt;/td>
&lt;td>&lt;code>e(wald_statistic)&lt;/code>, &lt;code>e(wald_df)&lt;/code>, &lt;code>e(wald_p)&lt;/code>, and &lt;code>e(wald_status)&lt;/code> (&lt;code>&amp;quot;computed&amp;quot;&lt;/code>, &lt;code>&amp;quot;unavailable&amp;quot;&lt;/code>, &lt;code>&amp;quot;not_applicable&amp;quot;&lt;/code>, &lt;code>&amp;quot;not_computed&amp;quot;&lt;/code>)&lt;/td>
&lt;td>&lt;code>r(CvM)&lt;/code>, &lt;code>r(CvMb)&lt;/code> (a B-by-1 draw vector), &lt;code>r(CvMcval)&lt;/code>, &lt;code>r(CvMpval)&lt;/code>, and &lt;code>r(status)&lt;/code> (&lt;code>&amp;quot;available&amp;quot;&lt;/code>, &lt;code>&amp;quot;unavailable&amp;quot;&lt;/code>, &lt;code>&amp;quot;not_applicable&amp;quot;&lt;/code>), &lt;code>r(reason)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Availability &amp;amp; rank requirements&lt;/td>
&lt;td>Requires &lt;strong>every&lt;/strong> such pretreatment cell to be available, their joint covariance to be well conditioned, and $\text{df} \le C - 1$ (or $N_F - 1$ without clustering). Never tests a subset.&lt;/td>
&lt;td>Requires &lt;strong>every&lt;/strong> such pretreatment cell to be identified and &lt;code>covars()&lt;/code> to be nonmissing for &lt;strong>every&lt;/strong> unit of $F$.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;blockquote>
&lt;p>[!NOTE]
&lt;strong>Cluster rank bound for the joint Wald test:&lt;/strong> Centered influence-function sums across $C$ clusters have covariance rank at most $C - 1$. If the number of pretreatment restrictions exceeds $C - 1$, the joint Wald test is reported as &lt;code>e(wald_status) = &amp;quot;unavailable&amp;quot;&lt;/code> even if floating-point rounding yields positive Cholesky pivots. Point estimates and cell/aggregate confidence intervals remain available.&lt;/p>
&lt;/blockquote>
&lt;h2 id="4-conditional-process-interpretation">4. Conditional process interpretation&lt;/h2>
&lt;p>The conditional test evaluates the covariates of the treatment adjustment at the earlier date of each cell, for every unit of the study population. Covariates used only in the observation model are not used for this evaluation. The residuals follow &lt;code>method(ipw|reg|dr)&lt;/code> and the correction for missing outcomes; they are not residuals of a regression of outcome levels. If covariate values are missing, or if a pretreatment cell is not identified, the chained test is unavailable. Neither test replaces the joint null hypothesis with a subset.&lt;/p>
&lt;p>&lt;code>cdid_pretest&lt;/code> always uses multiplier draws for its CvM distribution, including when its validated &lt;code>bstrap()&lt;/code>/&lt;code>cband()&lt;/code> flags are zero. Its default is IPW. The CvM statistic is unstandardized; KS, covariance and Wald slots are absent. A pretest p-value does not establish parallel trends, and selecting a specification after testing requires its own inference argument.&lt;/p>
&lt;h2 id="5-examples">5. Examples&lt;/h2>
&lt;p>Section 8 executes the fitted-model Wald inspection and the separate conditional test:&lt;/p>
&lt;pre>&lt;code class="language-stata">* 8a. The pretrend Wald test stored in `e()`
cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) biters($CDID_DEMO_BITERS)
display as text &amp;quot;Wald test status: &amp;quot; as result &amp;quot;`e(wald_status)'&amp;quot; ///
as text &amp;quot; chi2(&amp;quot; as result e(wald_df) as text &amp;quot;) = &amp;quot; as result %9.4f e(wald_statistic) ///
as text &amp;quot; p = &amp;quot; as result %6.4f e(wald_p)
* 8b. Conditional pretrend CvM test (`cdid_pretest`)
* The default treatment adjustment is `ipw`; `e()` from `cdid` is unchanged.
cdid_pretest y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
biters($CDID_DEMO_BITERS)
return list
* 8c. Conditional pretrend test under `selection(conditional_mtar)`
cdid_pretest y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) selection(conditional_mtar) selmodel(pair_logit) selpooling(separate) ///
selcovars(i.x_bin c.x_cont c.z_sel) biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 17 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/">Compare model robustness across treatment and missing outcome adjustments&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/">Options reference&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Cohort-by-date fixed effects</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/cohort-time-fe/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/cohort-time-fe/</guid><description>&lt;p>Use &lt;code>preset(cohort_time_fe)&lt;/code> for an absorbing treatment and a linear fixed-effects specification of untreated outcomes with unit effects and common date effects. Each treated cohort can have a different effect at each date. The fit uses the changes across each unit&amp;rsquo;s observed dates, including changes that span gaps. The preset corresponds to &lt;code>control = list(preset = &amp;quot;cohort_time_fe&amp;quot;)&lt;/code> of &lt;a href="https://github.com/dvbn/cdid" target="_blank" rel="noopener">R &lt;code>cdid&lt;/code> 1.3.0.0&lt;/a>.&lt;/p>
&lt;h2 id="fit-the-model">Fit the model&lt;/h2>
&lt;p>Supply long data with one row per unit and date, an outcome and the cohort variable, coded with the adoption date and zero for never-treated units. Include at least one never-treated cohort, use positive consecutive integer study dates, and place every adoption after the first study date. Rows with missing outcomes can stay in the data, and &lt;code>frame()&lt;/code> can supply units with no observed outcome.&lt;/p>
&lt;p>The example uses the panel of &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/get-started/">Get started&lt;/a>: 600 units observed from 2001 to 2008, with one outcome in five missing.&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261116
set obs 600
generate id = _n
generate G = cond(runiform() &amp;lt; .4, 0, cond(runiform() &amp;lt; .5, 2004, 2006))
generate x = rnormal()
expand 8
bysort id: generate year = 2000 + _n
generate y = x + .2*(year - 2000) + (G &amp;gt; 0 &amp;amp; year &amp;gt;= G)*(1 + .25*(year - G)) + rnormal()
replace y = . if runiform() &amp;lt; .2
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(year) gvar(G) preset(cohort_time_fe) method(reg) baseperiod(universal) controlgroup(nevertreated) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 600
Method: linear regression with fixed effects Number of cells = 14
Cohort-by-date fixed effects (within)
Control group: never treated; base period: universal
------------------------------------------------------------------------------
Group Time Role ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
2004 2001 pre -.1003211 .1614878 -.4168314 .2161892
2004 2002 pre .04890602 .1603049 -.2652857 .3630978
2004 2004 post .6800819 .1596719 .3671307 .9930331
2004 2005 post 1.275351 .1669978 .9480411 1.60266
2004 2006 post 1.345052 .159823 1.031805 1.658299
2004 2007 post 1.652869 .1643671 1.330715 1.975022
2004 2008 post 1.981949 .1596912 1.66896 2.294938
2006 2001 pre .003069 .1588206 -.3082137 .3143517
2006 2002 pre .1196553 .1610641 -.1960245 .4353351
2006 2003 pre -.05484205 .1554356 -.3594902 .2498061
2006 2004 pre -.3042621 .1624833 -.6227235 .01419928
2006 2006 post .7819229 .1453564 .4970295 1.066816
2006 2007 post 1.095659 .1693169 .7638035 1.427514
2006 2008 post 1.730351 .1625521 1.411755 2.048948
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
Pretrend Wald test (pre-treatment cells): chi2(6) = 8.83, Prob &amp;gt; chi2 = 0.1835
&lt;/code>&lt;/pre>
&lt;p>With never-treated controls, the date immediately before adoption is the reference, and the other pretreatment cells are estimated deviations; the footer tests them jointly when their covariance allows it. With &lt;code>method(reg)&lt;/code>, this is the linear regression of the outcome on unit fixed effects, date fixed effects and a separate effect for each treated cohort and date, fitted on the observed rows by least squares within units.&lt;/p>
&lt;p>For a common untreated path across both never-treated and not-yet-treated cohorts, use &lt;code>controlgroup(notyettreated) ptassumption(all)&lt;/code> with &lt;code>ptstart()&lt;/code> at the first study date. That model imposes the common path on all untreated cells from the first date and reports post-treatment effects only; its pretreatment restrictions are part of the fitted model.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(year) gvar(G) preset(cohort_time_fe) method(reg) baseperiod(universal) controlgroup(notyettreated) ptassumption(all) ptstart(2001) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;p>The preset requires &lt;code>baseperiod(universal)&lt;/code>, &lt;code>anticipation(0)&lt;/code> and no sampling weights. With &lt;code>method(reg)&lt;/code>, &lt;code>gmmweighting()&lt;/code> may be omitted or set to &lt;code>within&lt;/code>. &lt;code>cluster()&lt;/code> and the multiplier-bootstrap options apply as usual, and &lt;code>estat&lt;/code> aggregates the cells. With &lt;code>selection(none)&lt;/code>, the default, the observed changes must satisfy the model&amp;rsquo;s within-unit mean restriction; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a> when observation may be selective.&lt;/p>
&lt;h2 id="adjust-for-covariates">Adjust for covariates&lt;/h2>
&lt;p>Covariates in the varlist let the untreated calendar path and each cohort-by-date effect vary with time-invariant covariates: the design has common date-specific slopes and separate cohort-by-date deviations, with &lt;code>outcomepooling(separate)&lt;/code>. Supply the covariates for every unit of the study population, including units observed once or never. The reported effect averages the fitted contrast over the cohort in the study population, so a unit without an observed change contributes to that covariate average and to the influence functions. The fit reports rank deficiency or numerical singularity of the covariate design, and cells that the observed changes do not connect to the calendar path remain unavailable.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x, ivar(id) time(year) gvar(G) preset(cohort_time_fe) method(reg) baseperiod(universal) bstrap(0) cband(0)
estat dynamic
&lt;/code>&lt;/pre>
&lt;h2 id="treatment-weighting-and-doubly-robust-adjustment">Treatment weighting and doubly robust adjustment&lt;/h2>
&lt;p>&lt;code>method(ipw)&lt;/code> reweights clean comparison units to each treated cohort&amp;rsquo;s covariate distribution. &lt;code>method(dr)&lt;/code> combines a shared untreated change model with reweighted residuals. Both estimate the average untreated change separately for each cohort over its whole study population. Propensity models use the target and donor cohorts and include an intercept. With never-treated controls only the never-treated cohort is a donor; with not-yet-treated controls, each other cohort is a donor for changes that end before its adoption. The DR outcome model fits a shared linear calendar path to clean changes. The default &lt;code>gmmweighting(optimal)&lt;/code> uses the covariance of the unit moment scores, and &lt;code>gmmweighting(identity)&lt;/code> gives equal weight to each retained moment.&lt;/p>
&lt;p>These fits require overlap between each treated cohort and the clean donors. With &lt;code>selection(none)&lt;/code>, a sufficient condition is that the observations behind each cohort and date pair preserve its covariate distribution and conditional mean change. Given those conditions and parallel trends, DR is consistent when either the treatment propensity or the untreated change model is correct.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x, ivar(id) time(year) gvar(G) preset(cohort_time_fe) method(dr) baseperiod(universal) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;h2 id="adjust-for-selective-observation">Adjust for selective observation&lt;/h2>
&lt;p>&lt;code>selection(conditional_mtar)&lt;/code> applies when the observed changes represent the cohort&amp;rsquo;s changes conditional on the covariates of the observation or imputation model. Choose the treatment method with &lt;code>method()&lt;/code> and the observation correction with &lt;code>selmethod()&lt;/code>:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Observation correction&lt;/th>
&lt;th>Response for each unit and supported pair of dates&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>selmethod(ipw)&lt;/code>&lt;/td>
&lt;td>The observed change divided by its probability of being observed, or zero when either outcome is missing.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(imputation)&lt;/code>&lt;/td>
&lt;td>The fitted conditional mean change for that cohort and pair.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(dr)&lt;/code>&lt;/td>
&lt;td>The fitted conditional mean change plus the observed residual divided by its observation probability. A unit with a missing change contributes the fitted mean.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>selmodel(independent_period_logit)&lt;/code>, which assumes that observation at the two dates of a pair is independent given the covariates, and both imputation corrections use the whole study population (&lt;code>seluniverse(F)&lt;/code>); &lt;code>seluniverse(B)&lt;/code> and &lt;code>seluniverse(A)&lt;/code> require &lt;code>selmodel(pair_logit)&lt;/code> and &lt;code>selmethod(ipw)&lt;/code>, and the probability that a unit of the cohort belongs to the fitting units is then estimated by its share in the cohort. Fitted observation probabilities are bounded below by $10^{-6}$. Covariates must be constant within units and nonmissing for every unit; &lt;code>missingreference(exclude)&lt;/code> is not available with the preset. The standard errors include the estimation of the observation, imputation, outcome and propensity models.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x, ivar(id) time(year) gvar(G) preset(cohort_time_fe) method(dr) selection(conditional_mtar) selmethod(dr) baseperiod(universal) bstrap(0) cband(0) keepnuisance
cdid_nuisance
&lt;/code>&lt;/pre>
&lt;p>&lt;code>cdid_nuisance&lt;/code> lists the calendar regression, the treatment logits and, with a correction for missing outcomes, the observation logits and imputation regressions; see &lt;code>help cdid_nuisance&lt;/code>. &lt;code>cdid_chain&lt;/code> is not available after the preset, whose estimates do not come from chained comparisons.&lt;/p>
&lt;h2 id="comparison-with-regression-commands">Comparison with regression commands&lt;/h2>
&lt;p>The documentation of the R package &lt;code>cdid&lt;/code> reports that the regression fit of its preset matches R &lt;code>etwfe&lt;/code> and Stata &lt;code>jwdid&lt;/code> on the same inputs. The Stata preset was compared with R &lt;code>cdid&lt;/code>, not directly with &lt;code>jwdid&lt;/code>. Standard errors use the unit score sandwich without a degrees-of-freedom adjustment, so they differ from regression standard errors that apply one. On incomplete panels, check that each command uses the same observations, and compare aggregations only after aligning their cell weights: &lt;code>estat&lt;/code> weights cohorts by their size in the study population.&lt;/p>
&lt;h2 id="how-the-changes-are-combined">How the changes are combined&lt;/h2>
&lt;p>For the regression fit, eliminating a unit intercept gives the same least-squares objective as forming consecutive differences along that unit&amp;rsquo;s observed dates and weighting them by the inverse of their joint covariance under uncorrelated level errors with equal variance. A unit observed at dates 1, 3 and 4 contributes changes from 1 to 3 and from 3 to 4, which share the outcome at date 3; the fit accounts for that dependence. Inference uses the empirical unit or cluster scores. Treatment IPW and DR instead combine observed changes and cohort-standardized untreated changes by GMM.&lt;/p>
&lt;hr>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Compare model robustness across treatment and missing outcome adjustments</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/</guid><description>&lt;p>When baseline covariates influence which units enter treatment, how untreated outcomes evolve over time, and which outcomes are recorded across dates, chained difference-in-differences (&lt;code>cdid&lt;/code>, Bellégo, Benatia and Dortet-Bernadet 2025; Callaway and Sant&amp;rsquo;Anna 2021) separates estimation into two modeling layers: &lt;strong>treatment adjustment&lt;/strong> (&lt;code>method(ipw|reg|dr)&lt;/code>) and &lt;strong>handling missing outcomes&lt;/strong> (&lt;code>selection(none|conditional_mtar)&lt;/code> and &lt;code>selmethod(ipw|imputation|dr)&lt;/code>).&lt;/p>
&lt;p>This article defines the four nuisance models across the two layers, summarizes the large-sample consistency conditions for each supported combination, and walks through five model-correctness scenarios. For full mathematical definitions, see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/">Treatment adjustment&lt;/a> and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>.&lt;/p>
&lt;h2 id="1-the-four-labeled-nuisance-models-across-two-layers">1. The four labeled nuisance models across two layers&lt;/h2>
&lt;p>To recover average treatment effects for the study population $F$ in &lt;code>frame()&lt;/code>, &lt;code>cdid&lt;/code> uses up to four labeled nuisance models across two layers:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Symbol&lt;/th>
&lt;th>Model name&lt;/th>
&lt;th>Layer and Stata options&lt;/th>
&lt;th>What it models and where it is fitted&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>$p$&lt;/td>
&lt;td>Treatment propensity model&lt;/td>
&lt;td>Treatment adjustment (&lt;code>method(ipw)&lt;/code> or &lt;code>method(dr)&lt;/code>, using &lt;code>covars()&lt;/code> / &lt;code>indepvars&lt;/code>)&lt;/td>
&lt;td>For each distinct risk set, a logit model of membership in target cohort $g$ versus &lt;code>controlgroup()&lt;/code>, weighted according to the correction for missing outcomes.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$m$&lt;/td>
&lt;td>Counterfactual untreated change regression&lt;/td>
&lt;td>Treatment adjustment (&lt;code>method(reg)&lt;/code> or &lt;code>method(dr)&lt;/code>, with &lt;code>outcomepooling(separate|pooled)&lt;/code>, using &lt;code>covars()&lt;/code> / &lt;code>indepvars&lt;/code>)&lt;/td>
&lt;td>Weighted least squares regression fitted on control units per comparison block $b = (e, K)$ by default (&lt;code>outcomepooling(separate)&lt;/code>: $m_b(X) = \alpha_b + L(e), z(X)'\beta_b$) or jointly across blocks (&lt;code>outcomepooling(pooled)&lt;/code>: $m_b(X) = \alpha_b + L(e), z(X)'\beta$).&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$q$&lt;/td>
&lt;td>Observation pair probability model&lt;/td>
&lt;td>Handling missing outcomes (&lt;code>selection(conditional_mtar)&lt;/code> with &lt;code>selmethod(ipw)&lt;/code> or &lt;code>selmethod(dr)&lt;/code>, using &lt;code>selcovars()&lt;/code>)&lt;/td>
&lt;td>For each needed cohort and date pair cell $c = (k, e)$, a logit model $q_c(W)$ for observing both dates of pair $e$, either directly (&lt;code>selmodel(pair_logit)&lt;/code>) or as the product of two date logits (&lt;code>selmodel(independent_period_logit)&lt;/code>).&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$j$&lt;/td>
&lt;td>Actual cohort change imputer&lt;/td>
&lt;td>Handling missing outcomes (&lt;code>selection(conditional_mtar)&lt;/code> with &lt;code>selmethod(imputation)&lt;/code> or &lt;code>selmethod(dr)&lt;/code>, using &lt;code>covars()&lt;/code> / &lt;code>indepvars&lt;/code>)&lt;/td>
&lt;td>For each needed cohort and date pair cell $c = (k, e)$, a weighted least squares linear model $j_c(X) = \alpha_{k,e} + L(e), z(X)'\beta_r$ fitted to observed changes of cohort $k$, &lt;strong>treatment effects included&lt;/strong>, and evaluated across every unit of cohort $k$ in $F$.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="2-correctness-conditions-across-both-layers">2. Correctness conditions across both layers&lt;/h2>
&lt;p>Every consistency result below is a large-sample property that requires:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Scientifically sufficient conditioning:&lt;/strong> Supplying variables in &lt;code>covars()&lt;/code> or &lt;code>selcovars()&lt;/code> does not prove sufficiency; the covariates must justify conditional parallel trends and conditional mean trends missing at random ($E[Y_t - Y_s \mid W, G = k, S_{s,t} = 1] = E[Y_t - Y_s \mid W, G = k]$) in the population.&lt;/li>
&lt;li>&lt;strong>Overlap and support in the population, with the probability bounds not binding:&lt;/strong> Treatment propensities stay strictly below one, observation probabilities stay strictly positive where $q$ is fitted, imputation cells have positive training mass and prediction support where $j$ is fitted, the fitted models converge to regular interior limits, and all comparisons combined by GMM satisfy valid moment conditions for the same parameter.&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Correction for missing outcomes&lt;/th>
&lt;th>&lt;code>method(ipw)&lt;/code>&lt;/th>
&lt;th>&lt;code>method(reg)&lt;/code>&lt;/th>
&lt;th>&lt;code>method(dr)&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>selection(none)&lt;/code> with representative pair mean changes (no $q$ or $j$)&lt;/td>
&lt;td>$p$ correct&lt;/td>
&lt;td>$m$ correct across all blocks&lt;/td>
&lt;td>$p$ correct &lt;strong>or&lt;/strong> $m$ correct&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection(conditional_mtar) selmethod(ipw)&lt;/code> (fits $q$)&lt;/td>
&lt;td>$q$ correct in every cell &lt;strong>and&lt;/strong> $p$ correct&lt;/td>
&lt;td>$q$ correct in every cell &lt;strong>and&lt;/strong> $m$ correct&lt;/td>
&lt;td>$q$ correct in every cell &lt;strong>and&lt;/strong> ($p$ correct &lt;strong>or&lt;/strong> $m$ correct)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection(conditional_mtar) selmethod(imputation)&lt;/code> (fits $j$)&lt;/td>
&lt;td>$j$ correct in every cell/group &lt;strong>and&lt;/strong> $p$ correct&lt;/td>
&lt;td>$j$ correct in every cell/group &lt;strong>and&lt;/strong> $m$ correct&lt;/td>
&lt;td>$j$ correct in every cell/group &lt;strong>and&lt;/strong> ($p$ correct &lt;strong>or&lt;/strong> $m$ correct)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection(conditional_mtar) selmethod(dr)&lt;/code> (fits $q$ and $j$)&lt;/td>
&lt;td>For every needed cell $c$, ($q_c$ correct &lt;strong>or&lt;/strong> $j_c$ correct), &lt;strong>and&lt;/strong> $p$ correct&lt;/td>
&lt;td>For every needed cell $c$, ($q_c$ correct &lt;strong>or&lt;/strong> $j_c$ correct), &lt;strong>and&lt;/strong> $m$ correct&lt;/td>
&lt;td>For every needed cell $c$, ($q_c$ correct &lt;strong>or&lt;/strong> $j_c$ correct), &lt;strong>and&lt;/strong> ($p$ correct &lt;strong>or&lt;/strong> $m$ correct)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h3 id="four-qualifications">Four qualifications&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>Treatment DR supplies no general correction for a wrong imputer:&lt;/strong> Under pure imputation (&lt;code>selmethod(imputation)&lt;/code>), the sufficient condition requires a correct $j$ within each needed cell/pooling group. Choosing &lt;code>method(dr)&lt;/code> provides the $p$-or-$m$ alternative &lt;em>after&lt;/em> cohort changes are reconstructed; it does not generally repair biased reconstructed changes from a misspecified $j$. (These conditions are sufficient, not necessary: special projection or aggregation cancellations can still occur.)&lt;/li>
&lt;li>&lt;strong>Coupling through shared fits:&lt;/strong> When &lt;code>outcomepooling(pooled)&lt;/code> shares one slope vector $\beta$ across all comparison blocks in $m$, and when &lt;code>imppooling()&lt;/code>, &lt;code>selpooling()&lt;/code>, or &lt;code>selmodel(independent_period_logit)&lt;/code> shares parameters across cells or dates, misspecification in one cell or block can shift a shared slope everywhere it is used (whereas default &lt;code>outcomepooling(separate)&lt;/code> isolates $\beta_b$ to block $b$).&lt;/li>
&lt;li>&lt;strong>Common conditioning set $W$ and covariates only in &lt;code>selcovars()&lt;/code>:&lt;/strong> Under the augmented correction (&lt;code>selmethod(dr)&lt;/code>), &lt;code>covars()&lt;/code> builds $j$, $m$, and $p$ from covariates $X$, whereas &lt;code>selcovars()&lt;/code> builds $q$ from $W = (X, Z)$. Variables $Z$ listed only in &lt;code>selcovars()&lt;/code> never enter $j$, $m$, or $p$. If $Z$ shifts the conditional mean of actual changes given $W$ but is omitted from &lt;code>covars()&lt;/code>, $j_c(X)$ cannot generally represent that $W$-conditional mean, so the condition that the imputer is correct fails; a correct $q_c(W)$ together with valid treatment adjustment on $W$ provides the alternative condition. Adding extra variables to &lt;code>selcovars()&lt;/code> is therefore not automatically harmless.&lt;/li>
&lt;li>&lt;strong>Every model used must be estimable:&lt;/strong> the logits must pass their rank checks and have interior estimates, and the regressions must pass their rank, conditioning and prediction-support checks, even when the other model of a doubly robust pair is correct; &lt;code>cdid&lt;/code> does not fall back to another estimator. A completely observed or completely unobserved cell with a free intercept in $q$ stops estimation with &lt;code>r(498)&lt;/code>. Pure imputation (&lt;code>selmethod(imputation)&lt;/code>) runs on fully observed cells because it fits no $q$, whereas &lt;code>selmethod(dr)&lt;/code> stops whenever any model it uses ($q$, $j$, and $p$ or $m$ as required by &lt;code>method()&lt;/code>) cannot be estimated.&lt;/li>
&lt;/ol>
&lt;h2 id="3-five-misspecification-scenarios">3. Five misspecification scenarios&lt;/h2>
&lt;p>These are theoretical examples of sufficient conditions; they do not describe the simulated data of the hands-on do-file. Consider five specifications on a study population with treatment covariates &lt;code>x_bin x_cont&lt;/code> and an additional observation-shifting covariate &lt;code>z_sel&lt;/code>:&lt;/p>
&lt;ul>
&lt;li>&lt;code>fit_none_dr&lt;/code>: &lt;code>selection(none) method(dr)&lt;/code>&lt;/li>
&lt;li>&lt;code>fit_obs_or&lt;/code>: &lt;code>selection(conditional_mtar) selmethod(ipw) method(reg) selcovars(x_bin x_cont z_sel)&lt;/code>&lt;/li>
&lt;li>&lt;code>fit_obs_dr&lt;/code>: &lt;code>selection(conditional_mtar) selmethod(ipw) method(dr) selcovars(x_bin x_cont z_sel)&lt;/code>&lt;/li>
&lt;li>&lt;code>fit_imp_dr&lt;/code>: &lt;code>selection(conditional_mtar) selmethod(imputation) imppooling(separate) method(dr)&lt;/code>&lt;/li>
&lt;li>&lt;code>fit_aug_dr&lt;/code>: &lt;code>selection(conditional_mtar) selmethod(dr) imppooling(separate) method(dr) selcovars(x_bin x_cont z_sel)&lt;/code>&lt;/li>
&lt;/ul>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scenario&lt;/th>
&lt;th>Correct vs misspecified models&lt;/th>
&lt;th>&lt;code>fit_none_dr&lt;/code>&lt;/th>
&lt;th>&lt;code>fit_obs_or&lt;/code>&lt;/th>
&lt;th>&lt;code>fit_obs_dr&lt;/code>&lt;/th>
&lt;th>&lt;code>fit_imp_dr&lt;/code>&lt;/th>
&lt;th>&lt;code>fit_aug_dr&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>1. Baseline design:&lt;/strong> &lt;code>z_sel&lt;/code> shifts observation only; linear changes in &lt;code>x_bin x_cont&lt;/code>; logit $p(x)$ and pair-observation logits $q(x, z)$ (the default &lt;code>selmodel(pair_logit)&lt;/code>)&lt;/td>
&lt;td>$p, m, q, j$ all correct&lt;/td>
&lt;td>Generally biased&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>2. Nonlinear untreated trend:&lt;/strong> untreated changes depend on $x_{\mathrm{cont}}^2$, omitted from &lt;code>covars(x_bin x_cont)&lt;/code>&lt;/td>
&lt;td>$p, q$ correct; linear $m, j$ misspecified&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>3. Wrong observation model $q$:&lt;/strong> observation depends on $z_{\mathrm{sel}}^2$, omitted from &lt;code>selcovars(x_bin x_cont z_sel)&lt;/code>&lt;/td>
&lt;td>$j$ correct; $p, m$ valid on $W$; fitted $q$ misspecified&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>Consistent if the fitted $q$ has a regular interior limit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>4. Mispooled imputer $j$:&lt;/strong> set &lt;code>imppooling(within_cohort)&lt;/code> or &lt;code>across_cohorts&lt;/code> when treatment effects vary with $x$&lt;/td>
&lt;td>$q$ correct and $m, p$ valid; imposed $j$ pooling misspecified&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>Consistent&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>5. &lt;code>z_sel&lt;/code> also shifts outcomes:&lt;/strong> &lt;code>z_sel&lt;/code> shifts outcome trends but is omitted from &lt;code>covars(x_bin x_cont)&lt;/code> while included in &lt;code>selcovars(x_bin x_cont z_sel)&lt;/code>&lt;/td>
&lt;td>$q$ and $p$ correct on $W$; $j$ and $m$ omit outcome-shifting &lt;code>z_sel&lt;/code>&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>No guarantee from the conditions on $W$&lt;/td>
&lt;td>Consistent through $q$ and $p$&lt;/td>
&lt;td>No guarantee&lt;/td>
&lt;td>Consistent through $q$ and $p$&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>“Consistent” means that a sufficient large-sample condition holds under all stated assumptions and regular limits of the fitted models; “No guarantee” means those sufficient conditions no longer establish consistency (it does not prove bias for a specific cell or exclude special cancellation).&lt;/p>
&lt;h2 id="4-specifications-in-stata">4. Specifications in Stata&lt;/h2>
&lt;p>Sections 3, 4 and 5 of the hands-on do-file estimate the models without correction, with observation IPW, with pure imputation and with the augmented correction. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/">Treatment adjustment&lt;/a>, &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/observation-models/">Observation models&lt;/a> and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/change-imputation/">Change imputation&lt;/a> for the commands. The scenarios above are reasoning about sufficient conditions, not results of a simulation. The qualifications above on shared fits and on models that cannot be estimated apply.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 16 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/">GMM weighting and covariance regularization&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/inference/">Clustered inference, confidence bands, and pretrend tests&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Cross-pair chaining, control parallel trends and within-unit weighting</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/</guid><description>&lt;p>If a target cohort and its controls are observed over different intervals, they may have no pair of dates in common, and the comparisons that &lt;code>cdid&lt;/code> uses by default cannot identify the effect. Cross-pair chaining uses the changes of each cohort separately and links them through calendar dates where the trend assumptions apply. Specify &lt;code>crosspair&lt;/code> to allow these comparisons, and use &lt;code>cdid_chain&lt;/code> to see how they identify an effect.&lt;/p>
&lt;h2 id="what-is-estimated">What is estimated&lt;/h2>
&lt;p>For cohort $k$ and a pair of dates $s &amp;lt; t$ at which some units of cohort $k$ are observed, the link moment is the weighted mean outcome change of those units,&lt;/p>
&lt;p>$$
\hat m_{k,(s,t)} = \frac{\sum_i 1{G_i = k} O_{is} O_{it}, \omega_i, (Y_{it} - Y_{is})}{\sum_i 1{G_i = k} O_{is} O_{it}, \omega_i},
$$&lt;/p>
&lt;p>where $O_{it}$ indicates an observed outcome and $\omega_i$ the sampling weight. For each target cohort $g$, the links of $g$ itself are changes of its level path $\gamma_g(t)$, and the links of each clean control cohort are changes of the untreated path $\lambda_g(t)$ that the target would have followed. Both paths are anchored at the reference date $b_g$, the last date before $g - \delta$ (with $\delta$ the anticipation), where $\gamma_g(b_g) = \lambda_g(b_g) = 0$. The parameters are estimated jointly by GMM from all links, and&lt;/p>
&lt;p>$$
\text{ATT}(g,t) = \gamma_g(t) - \lambda_g(t), \qquad t \geq g.
$$&lt;/p>
&lt;p>Clean controls are the never-treated units and, with &lt;code>controlgroup(notyettreated)&lt;/code>, the cohorts $k$ not yet treated at the later date $t$ of the pair, allowing for anticipation ($t + \delta &amp;lt; k$). Pretreatment cells compare the target path with a control path on the same dates and are reported as pretrend contrasts. When several links of one cohort share the same set of observed units, the moments of a cycle of dates are linearly dependent; the estimator keeps a spanning forest of each such set and carries the dropped links in the GMM metric.&lt;/p>
&lt;h2 id="when-it-helps">When it helps&lt;/h2>
&lt;h3 id="contiguous-short-windows-need-only-pt-post">Contiguous short windows need only PT-post&lt;/h3>
&lt;p>In staggered designs where each cohort is observed for a few dates before adoption and the clean untreated dates of each control cohort form a contiguous interval, every step between a cohort&amp;rsquo;s reference date and a later date is usually covered by some cohort that is still untreated at both dates. Same-pair chained estimation with &lt;code>controlgroup(notyettreated)&lt;/code> and &lt;code>ptassumption(post)&lt;/code> then already identifies the post-treatment effects, including long horizons that a two-period comparison cannot reach. &lt;code>crosspair&lt;/code> is not needed for these designs; on complete panels both approaches use the same information, and &lt;code>crosspair&lt;/code> mainly changes how the comparisons are weighted.&lt;/p>
&lt;h3 id="non-overlapping-observation-pairs">Non-overlapping observation pairs&lt;/h3>
&lt;p>Suppose the target cohort 3 is observed at dates {1, 2, 4}, control cohort 4 at {2, 3} and control cohort 5 at {3, 4}. No control unit has an observed change over (2, 4), and no target unit is observed at date 3, so same-pair comparisons cannot identify ATT(3, 4). With &lt;code>crosspair&lt;/code>, the effect is identified by&lt;/p>
&lt;p>$$
\mathrm{ATT}(3, 4) = \mathbb{E}[Y_4 - Y_2 \mid G = 3] - \mathbb{E}[Y_3 - Y_2 \mid G = 4] - \mathbb{E}[Y_4 - Y_3 \mid G = 5],
$$&lt;/p>
&lt;p>under parallel trends between the target and the two control cohorts over the dates involved. &lt;code>cdid_chain&lt;/code> reports such a combination as the witness path &lt;code>2-&amp;gt;4 [g=3] - 2-&amp;gt;3 [ctrl{4}] - 3-&amp;gt;4 [ctrl{5}]&lt;/code>.&lt;/p>
&lt;h2 id="parallel-trends-choices">Parallel trends choices&lt;/h2>
&lt;p>For a target cohort $g$ with reference date $b_g$:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>&lt;code>ptassumption(post)&lt;/code>&lt;/strong> (default) assumes conditional parallel trends between cohort $g$ and the clean control cohorts from $b_g$ onward. Differences before $b_g$ are left free for each control pool.&lt;/li>
&lt;li>&lt;strong>&lt;code>ptassumption(ctrl)&lt;/code>&lt;/strong> keeps PT-post and assumes that the clean control cohorts share identical untreated trends from &lt;code>ptstart()&lt;/code> onward (by default the first study date). The target cohort&amp;rsquo;s own trend before $b_g$ remains unrestricted, so its pretreatment cells remain checks of its pretrends against the pooled controls.&lt;/li>
&lt;li>&lt;strong>&lt;code>ptassumption(all)&lt;/code>&lt;/strong> requires &lt;code>ptstart()&lt;/code> and restricts the control cohorts and the target cohort to common untreated trends from &lt;code>ptstart()&lt;/code> onward.&lt;/li>
&lt;/ul>
&lt;p>Across all target cohorts, not-yet-treated PT-post for the earliest treated cohort already implies equal untreated trends among the clean cohorts from that cohort&amp;rsquo;s reference date onward, so the additional restriction of PT-ctrl concerns earlier dates. If a control cohort has an idiosyncratic trend shift before $b_g$, PT-ctrl transmits that bias into post-treatment estimates, while PT-post leaves the shift unrestricted.&lt;/p>
&lt;h2 id="options">Options&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Effect with &lt;code>crosspair&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>method(ipw|reg|dr)&lt;/code>&lt;/td>
&lt;td>Covariates adjust each control link toward the target cohort: a treatment logit of the target cohort against the control units of the link (&lt;code>ipw&lt;/code>), a regression of the control changes on the covariates averaged over the target cohort (&lt;code>reg&lt;/code>), or both (&lt;code>dr&lt;/code>). Without covariates the three coincide. &lt;code>method(custom)&lt;/code> is not available.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>outcomepooling(separate|pooled)&lt;/code>&lt;/td>
&lt;td>Under &lt;code>method(reg|dr)&lt;/code>, a separate regression for each control cohort and pair of dates, or slopes common to all of them with separate intercepts.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Covariates and weights that vary over time&lt;/td>
&lt;td>Every comparison of target cohort $g$, including its control links, reads covariates at $g$&amp;rsquo;s reference date. Weights are read at the first study date (&lt;code>fixweights(first_period)&lt;/code>) or at the reference date (&lt;code>fixweights(base_period)&lt;/code>).&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection(conditional_mtar)&lt;/code>&lt;/td>
&lt;td>&lt;code>selmethod(ipw)&lt;/code> weights each observed change by the inverse of its fitted observation probability, with every &lt;code>selmodel()&lt;/code>, &lt;code>selpooling()&lt;/code> and &lt;code>seluniverse()&lt;/code>; &lt;code>selmethod(imputation)&lt;/code> and &lt;code>selmethod(dr)&lt;/code> predict the changes of every unit of the cohort and require &lt;code>seluniverse(F)&lt;/code>. The estimation of the observation and imputation models enters the influence functions.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gmmweighting(optimal|within|identity)&lt;/code>&lt;/td>
&lt;td>Inverse of the estimated covariance of the link moments, inverse of the analytical covariance of within-unit changes under uncorrelated level shocks, or the identity matrix.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>noconstant&lt;/code>, factor-variable covariates, &lt;code>frame()&lt;/code>, &lt;code>baseperiod()&lt;/code>, &lt;code>anticipation()&lt;/code>, &lt;code>controlgroup()&lt;/code>, &lt;code>cluster()&lt;/code>&lt;/td>
&lt;td>As without &lt;code>crosspair&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>crosspair&lt;/code> requires chained mode and is not available with &lt;code>method(custom)&lt;/code>, &lt;code>preset()&lt;/code> or &lt;code>dvar()&lt;/code>. Outcome-regression designs that are rank deficient on a control cohort without an exact alias that also holds on the target cohort are refused, because the counterfactual mean would not be identified without extrapolation.&lt;/p>
&lt;h2 id="the-stacked-cohort-fixed-effects-benchmark">The stacked cohort fixed-effects benchmark&lt;/h2>
&lt;p>Balla-Elliott and Norwich proposed linking successive control cohorts for cohorts with short pretreatment windows; their stacked cohort fixed-effects regression reproduces the calendar trend by linking those windows (&lt;a href="https://pdfs.dballaelliott.com/ccdid.pdf" target="_blank" rel="noopener">Cohort-Chained DiD&lt;/a>; see also &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/#cohort-chained-did">Estimate familiar DiD models with cdid&lt;/a> and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/short-pretreatment-windows/">Short pretreatment windows&lt;/a>). With &lt;code>controlgroup(notyettreated)&lt;/code>, &lt;code>baseperiod(universal)&lt;/code>, &lt;code>crosspair&lt;/code>, &lt;code>ptassumption(ctrl)&lt;/code> without &lt;code>ptstart()&lt;/code>, &lt;code>gmmweighting(within)&lt;/code>, no covariates, no correction for missing outcomes, the same unit weights and the same target and control sample for each slice, the point estimates equal the unit fixed-effects regression coefficients when observation windows are nested within each cohort, and the cohort fixed-effects coefficients when all units of a cohort share one window. The Stata test &lt;code>tests/stata/test_crosspair_stacked.do&lt;/code> compares these estimates with stacked regressions fitted with &lt;code>areg&lt;/code> (unit fixed effects) and &lt;code>regress&lt;/code> (cohort fixed effects) on short-window panels without never-treated units, with sampling weights, monotone attrition within cohorts (where only the unit fixed-effects coefficients coincide), dates missing from the calendar and one period of anticipation; the largest difference is $2.5 \times 10^{-13}$. Inference in &lt;code>cdid&lt;/code> uses its unit influence functions, not the regression standard errors.&lt;/p>
&lt;h2 id="inspect-the-identification-chains">Inspect the identification chains&lt;/h2>
&lt;p>&lt;code>cdid_chain&lt;/code> shows which effects need chaining, a combination of comparisons that identifies each effect, and the GMM weights of all comparisons. For every available cell, the contributions (weight times comparison estimate) sum to the reported estimate up to rounding.&lt;/p>
&lt;p>The example builds a panel in which each cohort is observed only during a short window before its treatment date, with no never-treated units. The last cohort has no not-yet-treated controls, so its cells are unavailable, and &lt;code>narm&lt;/code> restricts the event-study aggregation to the available cells.&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261111
set obs 240
generate long id = _n
generate int G = 2005 + mod(_n, 6)
generate double alpha = rnormal(0.7 * (G - 2005), 1.1)
expand 10
bysort id: generate int period = 2000 + _n
keep if period &amp;gt;= max(2001, G - 4)
generate double y = alpha + 0.35 * (period - 2001) + cond(period &amp;gt;= G, 2 + 0.5 * (period - G), 0) + rnormal(0, 0.45)
cdid y, ivar(id) time(period) gvar(G) controlgroup(notyettreated) baseperiod(universal) crosspair ptassumption(ctrl) gmmweighting(within) bstrap(0) cband(0)
cdid_chain, cohort(2006) time(2007)
estat dynamic, narm
&lt;/code>&lt;/pre>
&lt;p>The chain of cohort 2006 at 2007:&lt;/p>
&lt;pre>&lt;code class="language-text">Identification chains (cross-pair, ptassumption(ctrl), gmmweighting(within))
Comparisons used by GMM: 84 Overidentifying restrictions: 20
Cells: 1 (1 estimable, 0 chained without a direct comparison, 0 unavailable)
Group Time Role Chain ATT Std. err.
---------------------------------------------------------------
2006 2007 post direct 2.45420282 .118657047
witness: 2005-&amp;gt;2006 [g=2006] + 2006-&amp;gt;2007 [g=2006] - 2005-&amp;gt;2006 [ctrl{2007}] - 2006-&amp;gt;2007 [ctrl{2008}]
&lt;/code>&lt;/pre>
&lt;p>The event study over the available cells:&lt;/p>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 240
Method: doubly robust (dr) Number of event times = 15
Cross-pair comparisons; GMM weighting: within
Control group: not yet treated; base period: universal
Aggregation: dynamic
Event-time selection: narm
------------------------------------------------------------------------------
Event time ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
Overall 2.854236 .0753267 2.706598 3.001874
------------------------------------------------------------------------------
-9 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2010 at date 2001
(pre-treatment)
-8 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2009 at date 2001
(pre-treatment); cohort 2010 at date 2002 (pre-treatment)
-7 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2008 at date 2001
(pre-treatment); cohort 2009 at date 2002 (pre-treatment); cohort 2010 at date 2003
(pre-treatment)
-6 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2007 at date 2001
(pre-treatment); cohort 2008 at date 2002 (pre-treatment); cohort 2009 at date 2003
(pre-treatment); cohort 2010 at date 2004 (pre-treatment)
-5 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2006 at date 2001
(pre-treatment); cohort 2007 at date 2002 (pre-treatment); cohort 2008 at date 2003
(pre-treatment); cohort 2009 at date 2004 (pre-treatment); cohort 2010 at date 2005
(pre-treatment)
-4 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2005 at date 2001
(pre-treatment); cohort 2006 at date 2002 (pre-treatment); cohort 2007 at date 2003
(pre-treatment); cohort 2008 at date 2004 (pre-treatment); cohort 2009 at date 2005
(pre-treatment); cohort 2010 at date 2006 (pre-treatment)
-3 .04145277 .06193165 -.07993103 .1628366
-2 -.02531473 .05681671 -.1366734 .08604398
-1 0 0 0 0
0 1.931259 .05383278 1.825749 2.03677
1 2.443667 .07053394 2.305423 2.581911
2 2.883516 .08547695 2.715984 3.051048
3 3.356337 .1003161 3.159722 3.552953
4 3.656401 .1434481 3.375247 3.937554
5 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2005 at date 2010
(post-treatment)
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
The overall summary uses a pointwise interval.
Pretrend Wald test: not computed; some pre-treatment cells are unavailable, and the test is not
computed on a subset of them.
&lt;/code>&lt;/pre>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Bellégo, C., Benatia, D. and Dortet-Bernadet, V. (2025). The chained difference-in-differences. &lt;em>Journal of Econometrics&lt;/em>, 248, 105783.&lt;/li>
&lt;li>Balla-Elliott, D. and Norwich, A. Cohort-Chained DiD. Working paper. &lt;a href="https://pdfs.dballaelliott.com/ccdid.pdf" target="_blank" rel="noopener">https://pdfs.dballaelliott.com/ccdid.pdf&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 21 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/troubleshooting/">Diagnose errors and unavailable results&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/short-pretreatment-windows/">Short pretreatment windows and cross-pair chaining&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Custom estimators</title><link>https://www.davidbenatia.com/tools/cdid/stata/custom-estimators/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/custom-estimators/</guid><description>&lt;p>&lt;code>cdid&lt;/code> and &lt;code>cdid_pretest&lt;/code> can use your own estimator of each comparison instead of the built-in IPW, OR and DR estimators. The estimator is a Mata function, the &lt;em>callback&lt;/em>, named in the options&lt;/p>
&lt;pre>&lt;code class="language-text">method(custom) callback(my_att) [payload(my_settings)]
&lt;/code>&lt;/pre>
&lt;p>where &lt;code>my_settings&lt;/code> is an optional Mata object passed to the callback by pointer.&lt;/p>
&lt;h2 id="1-before-compiling-a-callback">1. Before compiling a callback&lt;/h2>
&lt;p>The structures &lt;code>cdid_callback_request&lt;/code> and &lt;code>cdid_callback_result&lt;/code> and the function &lt;code>cdid_callback_result_make()&lt;/code> are defined in the library &lt;code>lcdid_native.mlib&lt;/code>, which is installed with &lt;code>cdid&lt;/code>. In a new Stata session, index the library before compiling your callback:&lt;/p>
&lt;pre>&lt;code class="language-stata">mata: mata mlib index
&lt;/code>&lt;/pre>
&lt;h2 id="2-writing-a-callback">2. Writing a callback&lt;/h2>
&lt;p>The callback receives a &lt;code>struct cdid_callback_request scalar&lt;/code>, describing one comparison, and a &lt;code>pointer() scalar&lt;/code> to the payload (&lt;code>NULL&lt;/code> when &lt;code>payload()&lt;/code> is not specified). It returns the result of &lt;code>cdid_callback_result_make(att, psi, gradient)&lt;/code>, where &lt;code>att&lt;/code> is the estimate, &lt;code>psi&lt;/code> is the &lt;code>m x 1&lt;/code> influence function of the &lt;code>m&lt;/code> observations passed, and &lt;code>gradient&lt;/code> is the &lt;code>m x 1&lt;/code> derivative of &lt;code>att&lt;/code> with respect to the log weights, or &lt;code>J(0, 1, .)&lt;/code> when it is not supplied. The callback signals that it cannot estimate the comparison by raising an error, for example &lt;code>_error(459)&lt;/code>. The error stops chained estimation; in ordinary mode, the cell is reported as unavailable (&amp;ldquo;the callback stopped with an error&amp;rdquo;), and in the ordinary-mode &lt;code>cdid_pretest&lt;/code>, the test is reported as unavailable.&lt;/p>
&lt;p>The two callbacks below are used in the &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/examples/cdid_custom_estimators.do" target="_blank" rel="noopener">custom-estimator do-file&lt;/a>. &lt;code>my_att&lt;/code> estimates the weighted difference in mean outcome changes for panel comparisons; &lt;code>my_rcs_att&lt;/code> estimates the difference in differences of weighted means for comparisons of repeated cross sections. Both count their calls in the payload.&lt;/p>
&lt;pre>&lt;code class="language-stata">version 19.5
mata:
struct cdid_callback_result scalar my_att(
struct cdid_callback_request scalar r, pointer() scalar payload)
{
real scalar m, mt, mc
real colvector dy, wt, wc, psi
if (payload != NULL) *payload = *payload + 1
if (r.panel != 1) _error(498)
m = rows(r.D)
dy = r.y1 - r.y0
wt = r.i_weights :* r.D
wc = r.i_weights :* (1 :- r.D)
if (sum(wt) &amp;lt;= 0 | sum(wc) &amp;lt;= 0) _error(459)
mt = sum(wt :* dy) / sum(wt)
mc = sum(wc :* dy) / sum(wc)
psi = m :* (wt :* (dy :- mt) / sum(wt) - wc :* (dy :- mc) / sum(wc))
return(cdid_callback_result_make(mt - mc, psi, psi / m))
}
struct cdid_callback_result scalar my_rcs_att(
struct cdid_callback_request scalar r, pointer() scalar payload)
{
real scalar m, d, p, sign, mu, att
real colvector weight, psi
if (payload != NULL) *payload = *payload + 1
if (r.panel != 0) _error(498)
m = rows(r.D); att = 0; psi = J(m, 1, 0)
for (d = 0; d &amp;lt;= 1; d++) for (p = 0; p &amp;lt;= 1; p++) {
weight = r.i_weights :* (r.D :== d) :* (r.post :== p)
if (sum(weight) &amp;lt;= 0) _error(459)
mu = sum(weight :* r.y) / sum(weight)
sign = (d == p ? 1 : -1)
att = att + sign * mu
psi = psi + sign * m :* weight :* (r.y :- mu) / sum(weight)
}
return(cdid_callback_result_make(att, psi, J(0, 1, .)))
}
end
&lt;/code>&lt;/pre>
&lt;p>Use the callbacks on a simulated panel, after running the block above:&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261116
set obs 600
generate id = _n
generate G = cond(runiform() &amp;lt; .4, 0, cond(runiform() &amp;lt; .5, 2004, 2006))
generate x = rnormal()
expand 8
bysort id: generate year = 2000 + _n
generate y = x + .2*(year - 2000) + (G &amp;gt; 0 &amp;amp; year &amp;gt;= G)*(1 + .25*(year - G)) + rnormal()
replace y = . if runiform() &amp;lt; .2
mata: my_calls = 0
cdid y, ivar(id) time(year) gvar(G) method(custom) callback(my_att) payload(my_calls) bstrap(0) cband(0)
mata: my_calls
estat simple
&lt;/code>&lt;/pre>
&lt;p>The callbacks ignore covariates, so the varlist has none. The &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/examples/cdid_custom_estimators.do" target="_blank" rel="noopener">custom-estimator do-file&lt;/a> also runs them in ordinary mode and with &lt;code>cdid_pretest&lt;/code>.&lt;/p>
&lt;h2 id="3-fields-of-the-request">3. Fields of the request&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Field&lt;/th>
&lt;th>Type&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>mode&lt;/code>&lt;/td>
&lt;td>&lt;code>string scalar&lt;/code>&lt;/td>
&lt;td>&lt;code>&amp;quot;chained&amp;quot;&lt;/code> or &lt;code>&amp;quot;ordinary&amp;quot;&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>route&lt;/code>&lt;/td>
&lt;td>&lt;code>string scalar&lt;/code>&lt;/td>
&lt;td>Label of the type of comparison, for information: &lt;code>&amp;quot;baseline_static&amp;quot;&lt;/code>, &lt;code>&amp;quot;baseline_dated&amp;quot;&lt;/code> (covariates or weights that vary over time), &lt;code>&amp;quot;conditional_mtar_static&amp;quot;&lt;/code> or &lt;code>&amp;quot;conditional_mtar_dated&amp;quot;&lt;/code> in chained mode; &lt;code>&amp;quot;panel&amp;quot;&lt;/code>, &lt;code>&amp;quot;unbalanced_panel&amp;quot;&lt;/code> or &lt;code>&amp;quot;RCS&amp;quot;&lt;/code> in ordinary mode. Branch on &lt;code>mode&lt;/code> and &lt;code>panel&lt;/code> instead&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>panel&lt;/code>&lt;/td>
&lt;td>&lt;code>real scalar&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code> when outcomes are passed as pairs (&lt;code>y0&lt;/code>, &lt;code>y1&lt;/code>); &lt;code>0&lt;/code> when they are stacked (&lt;code>y&lt;/code>, &lt;code>post&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>inffunc&lt;/code>&lt;/td>
&lt;td>&lt;code>real scalar&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code> when &lt;code>psi&lt;/code> is required; &lt;code>0&lt;/code> when only the estimate is required (ordinary mode with &lt;code>noinffunc&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gradient_required&lt;/code>&lt;/td>
&lt;td>&lt;code>real scalar&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code> when the gradient is required (chained observation weighting); &lt;code>0&lt;/code> otherwise&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>g&lt;/code>, &lt;code>s&lt;/code>, &lt;code>t&lt;/code>&lt;/td>
&lt;td>&lt;code>real scalar&lt;/code>&lt;/td>
&lt;td>Cohort, base period, and comparison period&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>D&lt;/code>&lt;/td>
&lt;td>&lt;code>real colvector&lt;/code>&lt;/td>
&lt;td>&lt;code>m x 1&lt;/code> indicator: &lt;code>1&lt;/code> for units of cohort &lt;code>g&lt;/code>, &lt;code>0&lt;/code> for comparison units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>y0&lt;/code>, &lt;code>y1&lt;/code>&lt;/td>
&lt;td>&lt;code>real colvector&lt;/code>&lt;/td>
&lt;td>&lt;code>m x 1&lt;/code> outcomes in the base and comparison periods (&lt;code>panel == 1&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>y&lt;/code>, &lt;code>post&lt;/code>&lt;/td>
&lt;td>&lt;code>real colvector&lt;/code>&lt;/td>
&lt;td>&lt;code>m x 1&lt;/code> outcome and indicator of the comparison period (&lt;code>panel == 0&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>i_weights&lt;/code>&lt;/td>
&lt;td>&lt;code>real colvector&lt;/code>&lt;/td>
&lt;td>&lt;code>m x 1&lt;/code> observation weights&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>covariates&lt;/code>&lt;/td>
&lt;td>&lt;code>real matrix&lt;/code>&lt;/td>
&lt;td>&lt;code>m x p&lt;/code> covariate matrix&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>covariate_names&lt;/code>&lt;/td>
&lt;td>&lt;code>string rowvector&lt;/code>&lt;/td>
&lt;td>&lt;code>1 x p&lt;/code> names of the covariates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>rows_F&lt;/code>, &lt;code>rows_A&lt;/code>&lt;/td>
&lt;td>&lt;code>real colvector&lt;/code>&lt;/td>
&lt;td>Positions of the observations passed among the units of the study population and of the estimation sample; &lt;code>rows_A&lt;/code> is empty in ordinary mode&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>call_index&lt;/code>&lt;/td>
&lt;td>&lt;code>real scalar&lt;/code>&lt;/td>
&lt;td>Number of this call, starting at 1&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="4-where-callbacks-are-used">4. Where callbacks are used&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>Chained estimation without a missing-outcome correction&lt;/strong> (&lt;code>selection(none)&lt;/code>). &lt;code>att&lt;/code> and &lt;code>psi&lt;/code> must be finite. The gradient is optional; when it is omitted, &lt;code>cdid&lt;/code> uses &lt;code>psi / m&lt;/code>. When it is supplied, it must be a finite &lt;code>m x 1&lt;/code> vector.&lt;/li>
&lt;li>&lt;strong>Chained estimation with observation weighting&lt;/strong> (&lt;code>selection(conditional_mtar) selmethod(ipw)&lt;/code>), with any observation model, pooling and fitting universe. The gradient is required: the total derivative of &lt;code>att&lt;/code> with respect to the log weight of each observation passed, in the units of &lt;code>att&lt;/code> (not divided by &lt;code>m&lt;/code> or &lt;code>N&lt;/code>). &lt;code>selmethod(imputation)&lt;/code> and &lt;code>selmethod(dr)&lt;/code> do not support custom estimators.&lt;/li>
&lt;li>&lt;strong>Ordinary estimation&lt;/strong> (&lt;code>mode(ordinary)&lt;/code> or &lt;code>rcs&lt;/code>). The callback estimates each group-time effect from the two periods compared, in balanced panels (&lt;code>panel == 1&lt;/code>), unbalanced panels and repeated cross sections (&lt;code>panel == 0&lt;/code>). With &lt;code>noinffunc&lt;/code>, &lt;code>inffunc&lt;/code> is 0. The gradient is ignored. The influence function is used as returned; in particular, the adjustment that the built-in doubly robust estimator applies for repeated cross sections is not applied.&lt;/li>
&lt;li>&lt;strong>Conditional pretrend test, ordinary mode.&lt;/strong> &lt;code>cdid_pretest&lt;/code> calls the callback for each evaluation point and pretreatment cell, with the outcome replaced by the indicator-transformed outcome used by the test.&lt;/li>
&lt;li>&lt;strong>Conditional pretrend test, chained mode.&lt;/strong> The test is not defined for custom estimators. &lt;code>cdid_pretest&lt;/code> returns &lt;code>r(status) = &amp;quot;not_applicable&amp;quot;&lt;/code> with an explanation in &lt;code>r(reason)&lt;/code> and does not call the callback.&lt;/li>
&lt;li>&lt;strong>Covariates missing at a reference date.&lt;/strong> When &lt;code>missingreference(exclude)&lt;/code> restricts a cohort, the callback receives only the units eligible for that cohort&amp;rsquo;s comparisons, with weights computed on those units.&lt;/li>
&lt;li>&lt;strong>Not supported.&lt;/strong> &lt;code>method(custom)&lt;/code> is not available with &lt;code>crosspair&lt;/code>, &lt;code>gmmweighting(within)&lt;/code>, &lt;code>preset()&lt;/code> or &lt;code>dvar()&lt;/code>. &lt;code>cdid_chain&lt;/code> reports the comparisons and GMM weights of custom fits.&lt;/li>
&lt;li>&lt;strong>After estimation.&lt;/strong> &lt;code>cdid&lt;/code> stores the estimates, the influence functions, and the names of the callback and payload in &lt;code>e(callback)&lt;/code> and &lt;code>e(payload)&lt;/code>; &lt;code>cdid_pretest&lt;/code> returns the names in &lt;code>r(callback)&lt;/code> and &lt;code>r(payload)&lt;/code>, with the number of calls in &lt;code>r(n_callbacks)&lt;/code>, and &lt;code>cdid_pretest_load&lt;/code> does not restore them. &lt;code>estat&lt;/code>, &lt;code>cdid_plot&lt;/code>, &lt;code>cdid_export&lt;/code>, &lt;code>cdid_load&lt;/code> and &lt;code>cdid_pretest_load&lt;/code> use the stored results and never call the callback again; it need not exist after estimation.&lt;/li>
&lt;/ol>
&lt;p>See &lt;code>help cdid_custom&lt;/code> for the same information in Stata.&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a>&lt;/p></description></item><item><title>Diagnose errors and unavailable results</title><link>https://www.davidbenatia.com/tools/cdid/stata/help/troubleshooting/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/help/troubleshooting/</guid><description>&lt;p>&lt;code>cdid&lt;/code> checks the syntax and the data first, then estimates the models used for adjustment, determines which effects are identified, and finally computes the inference. A refused request stops with a message that names the condition that failed. An effect that the data cannot identify does not stop the command: it is reported as unavailable with a reason. A successful estimation does not show that its identifying assumptions hold.&lt;/p>
&lt;p>The examples on this page use the data of the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/hands-on/">hands-on do-file&lt;/a>: run its Sections 0 and 1 first.&lt;/p>
&lt;h2 id="read-the-error">Read the error&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Return code&lt;/th>
&lt;th>Usual meaning&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>198&lt;/td>
&lt;td>Invalid syntax or an option that does not apply, for example an option of &lt;code>gvar()&lt;/code> estimation used with &lt;code>dvar()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>459&lt;/td>
&lt;td>Data or a combination of options that the estimator cannot use: duplicate unit-date rows, weights that vary within units without &lt;code>fixweights()&lt;/code>, an incomplete specification, a rank-deficient design, or a covariate missing at a reference date under &lt;code>missingreference(error)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>498&lt;/td>
&lt;td>Results that do not fit the command, for example &lt;code>cdid_chain&lt;/code> when the current results are not a chained fit, or a file of the wrong type.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>908&lt;/td>
&lt;td>A limit set by &lt;code>workspace()&lt;/code>, &lt;code>chunk()&lt;/code> or &lt;code>workcap()&lt;/code>, or by Stata&amp;rsquo;s matrix size, would be exceeded.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Two incomplete specifications, as in Section 11 of the hands-on do-file:&lt;/p>
&lt;pre>&lt;code class="language-stata">capture noisily cdid y x_bin, ivar(id) time(period) gvar(first_treat) ptassumption(all)
display _rc
capture noisily cdid y x_bin, ivar(id) time(period) gvar(first_treat) selection(none) selmethod(dr)
display _rc
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">ptassumption(all) requires ptstart(#), which must be one of the periods in the data; ptstart() is not allowed with ptassumption(post).
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">selmethod(dr) requires selection(conditional_mtar).
&lt;/code>&lt;/pre>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Problem&lt;/th>
&lt;th>What to check&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Invalid combination of options or invalid data&lt;/td>
&lt;td>The mode, the missing-outcome options, the &lt;code>frame()&lt;/code> options, &lt;code>ptstart()&lt;/code> with &lt;code>ptassumption(all)&lt;/code>, and &lt;code>fixweights()&lt;/code> when weights vary over time. The &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/">options reference&lt;/a> lists the estimators that accept each option.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>No results, or results of another command&lt;/td>
&lt;td>Rerun &lt;code>cdid&lt;/code>, restore stored results with &lt;code>estimates restore&lt;/code>, or load saved results with &lt;code>cdid_load&lt;/code>. Datasets written by &lt;code>cdid_export&lt;/code> cannot be loaded as results.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Existing output file&lt;/td>
&lt;td>&lt;code>cdid_export&lt;/code>, &lt;code>cdid_plot&lt;/code> and &lt;code>cdid_chain&lt;/code> accept &lt;code>replace&lt;/code>; the &lt;code>saving()&lt;/code> option of &lt;code>cdid&lt;/code>, &lt;code>estat&lt;/code> and &lt;code>cdid_pretest&lt;/code> never overwrites a file, so choose a new name. The &lt;code>.dta&lt;/code> rule applies to &lt;code>cdid_export&lt;/code> and to &lt;code>cdid_plot, plotdata()&lt;/code>: a name with another extension is refused. &lt;code>cdid_plot, saving()&lt;/code> writes a &lt;code>.gph&lt;/code> file and &lt;code>export()&lt;/code> the graph formats of &lt;code>graph export&lt;/code>. Names created by &lt;code>tempfile&lt;/code> are accepted by all of them.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Memory or size limit&lt;/td>
&lt;td>&lt;code>workspace()&lt;/code>, &lt;code>chunk()&lt;/code> and &lt;code>workcap()&lt;/code> concern the main numerical arrays, not the total memory or time used by Stata, and do not relax any check of support or convergence. &lt;code>posting(state)&lt;/code> avoids Stata&amp;rsquo;s matrix size limit.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="inspect-a-completed-fit">Inspect a completed fit&lt;/h2>
&lt;p>&lt;code>cdid_diagnostics&lt;/code> summarizes the units, the cells by role and availability, the GMM weighting, the settings and the inference; &lt;code>cdid_diagnostics, detail&lt;/code> also lists each unavailable cell with its reason. &lt;code>cdid_chain&lt;/code> shows which comparisons identify each available cell, and &lt;code>cdid_nuisance&lt;/code> the fitted models after &lt;code>keepnuisance&lt;/code>.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) bstrap(0) cband(0)
cdid_diagnostics, detail
cdid_chain
&lt;/code>&lt;/pre>
&lt;h2 id="an-effect-is-unavailable">An effect is unavailable&lt;/h2>
&lt;p>The results keep every requested cell; unavailable cells have missing estimates and inference and a stated reason. With &lt;code>posting(matrix)&lt;/code>, only the available estimates are posted in &lt;code>e(b)&lt;/code>, and &lt;code>e(coef_map)&lt;/code> gives the cell of each coefficient. &lt;code>cdid_export, type(cells)&lt;/code> saves all cells with their reasons. Common reasons are that no comparison unit is observed at the dates involved, that a cohort g has no study date d with d + anticipation &amp;lt; g, and hence no reference date, that the observed changes of a cohort do not connect its reference date to the target date, or, under &lt;code>missingreference(exclude)&lt;/code>, that no eligible unit remains. Regularizing the GMM covariance cannot create a missing comparison. Remedies, when their assumptions are acceptable, are not-yet-treated controls, &lt;code>crosspair&lt;/code> for cohorts observed over different windows, or &lt;code>ptassumption(all)&lt;/code> or &lt;code>ptassumption(ctrl)&lt;/code>; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining&lt;/a>.&lt;/p>
&lt;p>&lt;code>narm&lt;/code> in &lt;code>estat&lt;/code> changes how an aggregation treats unavailable cells; it does not identify the missing effects. Check which cells were included and excluded in the dataset written by &lt;code>cdid_export, type(aggregate)&lt;/code> before interpreting the aggregation.&lt;/p>
&lt;h2 id="a-logit-model-has-no-finite-solution">A logit model has no finite solution&lt;/h2>
&lt;p>An observation logit with a free cell intercept has no finite estimate in a cell where every unit, or no unit, is observed; a treatment logit has none when a covariate value perfectly predicts cohort membership within a comparison. Pooling the slopes keeps the cell intercepts and does not solve the first problem. Pure imputation (&lt;code>selmethod(imputation)&lt;/code>) fits no observation logit, so it can be used when every outcome of a cell is observed and imputation is justified; it still needs enough observed changes and support for prediction. &lt;code>cdid&lt;/code> does not drop observations, change the pooling or switch estimators on its own. That another correction runs on the same data does not fix the original specification.&lt;/p>
&lt;h2 id="an-outcome-regression-or-imputation-design-is-refused">An outcome regression or imputation design is refused&lt;/h2>
&lt;p>A regression design that is rank deficient on its fitting rows is refused with error 459 and a message naming the regression. When the redundant columns are exactly collinear on every row used to fit and to predict (for example a covariate and a copy of it), the redundant column is dropped, as in R. Remove the redundant covariate, coarsen a factor variable, or use a coarser &lt;code>imppooling()&lt;/code>.&lt;/p>
&lt;h2 id="missing-covariates-or-weights-versus-missing-outcomes">Missing covariates or weights versus missing outcomes&lt;/h2>
&lt;p>A missing outcome is an expected input. A missing covariate or weight is not: time-invariant covariates must be complete for the units used, and covariates or weights that vary over time are needed at the dates where the comparisons read them. Under the default &lt;code>missingreference(exclude)&lt;/code>, a covariate missing at a cohort&amp;rsquo;s reference date excludes the unit from that cohort&amp;rsquo;s comparisons with a warning; under &lt;code>missingreference(error)&lt;/code>, the command stops and lists the missing values. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/#reference-dates-for-covariates-that-change-within-a-unit">Prepare your panel and unit table&lt;/a>.&lt;/p>
&lt;h2 id="pretrend-tests-are-unavailable">Pretrend tests are unavailable&lt;/h2>
&lt;p>The Wald test computed by &lt;code>cdid&lt;/code> requires every pretreatment cell and a valid joint covariance. Centered sums over $C$ clusters have rank at most $C - 1$, so too many restrictions, a singular covariance or a missing cell make the test unavailable; &lt;code>e(wald_status)&lt;/code> and &lt;code>e(wald_reason)&lt;/code> say why. Under &lt;code>missingreference(exclude)&lt;/code>, an unavailable pretrend comparison also makes the joint test unavailable. A subset of cells is never tested instead.&lt;/p>
&lt;p>The conditional test of &lt;code>cdid_pretest&lt;/code> needs every pretreatment cell of the request and the covariates of every unit of the study population at the relevant dates; it reports &lt;code>r(status)&lt;/code> and &lt;code>r(reason)&lt;/code>. It stops with error 459 when a required covariate is missing.&lt;/p>
&lt;h2 id="standard-errors-look-unusual">Standard errors look unusual&lt;/h2>
&lt;p>&lt;code>e(se)&lt;/code> holds the reported standard errors: with &lt;code>bstrap(1)&lt;/code>, the default, they come from the multiplier bootstrap and differ from the analytical &lt;code>e(analytic_se)&lt;/code>, and they change with the random-number stream. With few clusters, bootstrap and analytical standard errors can be unstable. Simultaneous bands are generally wider than pointwise intervals, but the bootstrap critical value of a band need not exceed the normal critical value of a pointwise interval. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/inference/">Inference&lt;/a>.&lt;/p>
&lt;h2 id="results-differ-from-ordinary-mode-or-from-csdid">Results differ from ordinary mode or from csdid&lt;/h2>
&lt;p>Chained and ordinary estimates agree only in the settings described in &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/#when-chained-and-ordinary-estimates-should-agree">Moving from did and csdid&lt;/a>. Ordinary mode drops the units that are not observed at every date unless &lt;code>allowunbalanced&lt;/code> is specified, and options specific to chained mode have no effect there.&lt;/p>
&lt;h2 id="commands-not-available-after-some-results">Commands not available after some results&lt;/h2>
&lt;pre>&lt;code class="language-stata">quietly cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) noinffunc
capture noisily estat simple
display _rc
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">estat aggregations need influence functions; refit cdid without noinffunc.
&lt;/code>&lt;/pre>
&lt;p>&lt;code>estat&lt;/code> needs the influence functions that &lt;code>noinffunc&lt;/code> omits. After &lt;code>estat&lt;/code>, &lt;code>cdid_chain&lt;/code> reports the comparisons of the fit computed in the same session, but &lt;code>cdid_nuisance&lt;/code> needs the fit: restore it with &lt;code>estimates restore&lt;/code>. After &lt;code>dvar()&lt;/code>, &lt;code>cdid_plot&lt;/code>, &lt;code>cdid_chain&lt;/code> and &lt;code>cdid_diagnostics&lt;/code> are not available, and &lt;code>estat&lt;/code> stops with a message that points to &lt;code>e(att)&lt;/code> and &lt;code>e(se_att)&lt;/code>.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 20 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/">Results reference&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining, control parallel trends and within-unit weighting&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Estimate familiar DiD models with cdid</title><link>https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/</guid><description>&lt;p>Several widely used difference-in-differences estimators correspond to particular settings of &lt;code>cdid&lt;/code>. This page states, for each, the settings, the sample and the estimand under which the point estimates coincide, and how the correspondence was checked for this guide. A numerical match is reported only where both sides were run in Stata on the same simulated data; the other correspondences are stated as specifications. Choose the comparison groups and treatment history first, then the treatment adjustment, then whether to correct for selective observation.&lt;/p>
&lt;h2 id="matched-specifications">Matched specifications&lt;/h2>
&lt;p>For a numerical match, use the same sample, outcome and covariates, the same untreated reference, and the same weights on the reported effects. Match the variance convention separately. Here &lt;code>g&lt;/code> is the first treatment date of an absorbing treatment, and &lt;code>d&lt;/code> is the current status of a binary treatment that can switch on and off.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>To reproduce&lt;/th>
&lt;th>Settings in &lt;code>cdid&lt;/code>&lt;/th>
&lt;th>Where the match holds&lt;/th>
&lt;th>Checked for this guide&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Callaway and Sant&amp;rsquo;Anna, Stata &lt;code>csdid&lt;/code>&lt;/td>
&lt;td>&lt;code>mode(ordinary)&lt;/code>, or a chained fit in the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/#when-chained-and-ordinary-estimates-should-agree">matched cases&lt;/a>&lt;/td>
&lt;td>Same two-date samples, comparison group, base period and adjustment.&lt;/td>
&lt;td>Run in Stata with &lt;code>csdid&lt;/code> 2.0.2: &lt;a href="#callaway-and-santanna-with-csdid">below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Wooldridge&amp;rsquo;s linear cohort-by-date regression (Stata &lt;code>jwdid&lt;/code>, &lt;code>xthdidregress twfe&lt;/code>; R &lt;code>etwfe&lt;/code>)&lt;/td>
&lt;td>&lt;code>preset(cohort_time_fe) method(reg)&lt;/code>&lt;/td>
&lt;td>Unit and date fixed effects with one effect per treated cohort and date; never-treated or not-yet-treated controls; time-invariant covariates.&lt;/td>
&lt;td>Run in Stata against the same regression fitted with &lt;code>areg&lt;/code>; &lt;code>jwdid&lt;/code> was not run. &lt;a href="#the-linear-cohort-by-date-regression">Below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Sun and Abraham, Stata &lt;code>eventstudyinteract&lt;/code>&lt;/td>
&lt;td>Same preset with &lt;code>controlgroup(nevertreated)&lt;/code>&lt;/td>
&lt;td>The saturated cohort-by-event-time regression with never-treated controls and the same reference period.&lt;/td>
&lt;td>Same regression as the row above; &lt;code>eventstudyinteract&lt;/code> was not run.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Borusyak, Jaravel and Spiess, Stata &lt;code>did_imputation&lt;/code>; Gardner, Stata &lt;code>did2s&lt;/code>&lt;/td>
&lt;td>Same preset with &lt;code>controlgroup(notyettreated) ptassumption(all)&lt;/code> and &lt;code>ptstart()&lt;/code> at the first date&lt;/td>
&lt;td>Complete, unweighted panel; untreated outcomes modeled with unit and date fixed effects.&lt;/td>
&lt;td>Run in Stata against the imputation computed with &lt;code>regress&lt;/code>; &lt;code>did_imputation&lt;/code> and &lt;code>did2s&lt;/code> were not run. &lt;a href="#two-stage-and-imputation-event-studies">Below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Two-date clean-control comparison (local-projection DiD)&lt;/td>
&lt;td>&lt;code>method(reg)&lt;/code> on the two dates, or the preset&lt;/td>
&lt;td>Complete panel, one adoption cohort, never-treated controls, no covariates.&lt;/td>
&lt;td>Run in Stata against &lt;code>regress&lt;/code> of the long difference. &lt;a href="#the-two-date-comparison">Below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Harmon&amp;rsquo;s stepwise DiD&lt;/td>
&lt;td>One two-date &lt;code>cdid&lt;/code> fit per consecutive step, summed&lt;/td>
&lt;td>Each step uses the cohorts still untreated at its later date.&lt;/td>
&lt;td>Run in Stata against the step differences of means. &lt;a href="#stepwise-did">Below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Balla-Elliott and Norwich&amp;rsquo;s Cohort-Chained DiD&lt;/td>
&lt;td>&lt;code>controlgroup(notyettreated) baseperiod(universal) crosspair ptassumption(ctrl) gmmweighting(within)&lt;/code>&lt;/td>
&lt;td>Stacked target-cohort regressions on the same sample and weights, without covariates.&lt;/td>
&lt;td>Tested in Stata against &lt;code>areg&lt;/code> and &lt;code>regress&lt;/code>: &lt;a href="#cohort-chained-did">below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>de Chaisemartin et al., static binary switchers, Stata &lt;code>did_multiplegt_stat&lt;/code>&lt;/td>
&lt;td>&lt;code>dvar(d) method(reg)&lt;/code>&lt;/td>
&lt;td>Complete panel, no covariates, switcher-weighted average of entries and exits.&lt;/td>
&lt;td>Not run in Stata for this guide; an R result is &lt;a href="#binary-static-switcher-summaries">cited below&lt;/a>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="callaway-and-santanna-with-csdid">Callaway and Sant&amp;rsquo;Anna with csdid&lt;/h2>
&lt;p>The examples on this page use a complete panel of 72 units over six dates: a third never treated, a third first treated at date 3 and a third at date 5. Each unit has a fixed effect, the untreated path is $\sin(t)$, and the effect grows with time since adoption.&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 14603
set obs 72
generate id = _n
generate g = cond(mod(id - 1, 3) == 0, 0, cond(mod(id - 1, 3) == 1, 3, 5))
generate a = rnormal()
expand 6
bysort id: generate t = _n
generate y = a + sin(t) + rnormal() + cond(g &amp;gt; 0 &amp;amp; t &amp;gt;= g, (t - g + 1) / 2, 0)
generate byte treated = g &amp;gt; 0 &amp;amp; t &amp;gt;= g
&lt;/code>&lt;/pre>
&lt;p>Ordinary mode computes its estimates with &lt;code>csdid&lt;/code> 2.0.2. Run directly, &lt;code>csdid&lt;/code> with not-yet-treated controls gives the same post-treatment cells; the pretreatment cells differ only because &lt;code>csdid&lt;/code> 2.0.2 uses a universal base period by default and &lt;code>cdid&lt;/code> a varying one. A chained fit with IPW, no covariates and never-treated controls also gives the same post-treatment cells on this complete panel, because the cohort means then telescope.&lt;/p>
&lt;pre>&lt;code class="language-stata">csdid y, ivar(id) time(t) gvar(g) notyet method(ipw)
matrix b_csdid = e(b)
cdid y, ivar(id) time(t) gvar(g) mode(ordinary) controlgroup(notyettreated) method(ipw) bstrap(0) cband(0)
matrix b_ordinary = e(b)
csdid y, ivar(id) time(t) gvar(g) nevertreated method(ipw)
matrix b_never = e(b)
cdid y, ivar(id) time(t) gvar(g) method(ipw) bstrap(0) cband(0)
matrix b_chained = e(b)
mata: post = (2, 3, 4, 5, 9, 10)
mata: max(abs(st_matrix(&amp;quot;b_csdid&amp;quot;)[post] - st_matrix(&amp;quot;b_ordinary&amp;quot;)[post]))
mata: max(abs(st_matrix(&amp;quot;b_never&amp;quot;)[post] - st_matrix(&amp;quot;b_chained&amp;quot;)[post]))
&lt;/code>&lt;/pre>
&lt;p>The two lines of output are the largest absolute differences over the six post-treatment cells, for ordinary mode against &lt;code>csdid&lt;/code> and for the chained fit against &lt;code>csdid&lt;/code> with never-treated controls:&lt;/p>
&lt;pre>&lt;code class="language-text"> 4.44089e-16
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> 1.77636e-15
&lt;/code>&lt;/pre>
&lt;p>Columns 2 to 5, 9 and 10 of &lt;code>e(b)&lt;/code> are the cells (3,3) to (3,6), (5,5) and (5,6) in both commands. Standard errors were not compared. In an incomplete panel, &lt;code>csdid&lt;/code>&amp;rsquo;s &lt;code>bal(pair)&lt;/code> keeps the units with both outcomes in each two-date comparison, whereas chained estimation can also combine other supported pairs into an effect, so the estimates generally differ.&lt;/p>
&lt;h2 id="the-linear-cohort-by-date-regression">The linear cohort-by-date regression&lt;/h2>
&lt;p>The preset with never-treated controls fits the regression of the outcome on unit fixed effects, date fixed effects and one indicator for each treated cohort and date other than the date before adoption. The same regression can be fitted with &lt;code>areg&lt;/code>:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(t) gvar(g) preset(cohort_time_fe) method(reg) baseperiod(universal) controlgroup(nevertreated) bstrap(0) cband(0)
matrix b_preset = e(b)
foreach c in 3 5 {
forvalues s = 1/6 {
if `s' != `c' - 1 generate byte D`c'_`s' = g == `c' &amp;amp; t == `s'
}
}
areg y i.t D3_* D5_*, absorb(id)
mata: max(abs(st_matrix(&amp;quot;b_preset&amp;quot;) - st_matrix(&amp;quot;e(b)&amp;quot;)[7..16]))
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> 1.09912e-14
&lt;/code>&lt;/pre>
&lt;p>The ten coefficients, including the four pretreatment deviations, match up to the printed difference. This is the specification of Wooldridge&amp;rsquo;s extended two-way fixed-effects regression (Stata &lt;code>jwdid&lt;/code>, &lt;code>xthdidregress twfe&lt;/code>) and, with never-treated controls, the saturated cohort-by-event-time regression of Sun and Abraham (&lt;code>eventstudyinteract&lt;/code>); those commands were not run for this guide. The R documentation of &lt;code>cdid&lt;/code> reports matches of the R preset with R &lt;code>etwfe&lt;/code> and Stata &lt;code>jwdid&lt;/code>. The preset&amp;rsquo;s standard errors use the unit score sandwich without a degrees-of-freedom adjustment, so they differ from the &lt;code>areg&lt;/code> standard errors shown; they were not compared.&lt;/p>
&lt;p>The match covers unit fixed effects, never-treated or not-yet-treated controls and time-invariant covariates, which let the untreated calendar path and the cohort-by-date effects vary with the covariates; each effect is then evaluated at the covariate mean of its cohort in the study population. The preset requires a never-treated cohort, unit weights, no anticipation and positive consecutive integer dates. When observation dates vary within a cohort, compare with a regression that has unit fixed effects. Specifications outside the preset, such as time-varying regressors, sampling weights or a common effect per event time (&lt;code>jwdid&lt;/code>&amp;rsquo;s &lt;code>hettype(event)&lt;/code>), have no counterpart in it. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cohort-time-fe/">Cohort-by-date fixed effects&lt;/a>.&lt;/p>
&lt;h2 id="how-event-study-averages-are-weighted">How event-study averages are weighted&lt;/h2>
&lt;p>An event-study point at horizon 1 averages effects measured one period after adoption. If the 2020 cohort has 60 units and an estimated effect of 1 in 2021, and the 2022 cohort has 40 units and an effect of 3 in 2023, the cohort-size-weighted point is $0.6 \times 1 + 0.4 \times 3 = 1.8$. If only 20 units of the later cohort have an observed outcome in 2023, an average weighted by observed outcomes is $(60 \times 1 + 20 \times 3) / 80 = 1.5$, with the same two cohort effects.&lt;/p>
&lt;p>To compare event studies, first compare the cohort-by-date effects, then average the same cohorts at each horizon with the same weights. &lt;code>estat dynamic&lt;/code> weights each cohort by its number of units in the study population, and averages over available cells only with &lt;code>narm&lt;/code>. Regression postestimation commands often average over observed treated rows. On a complete panel the two weightings coincide when the samples and supported cohorts are the same.&lt;/p>
&lt;h2 id="two-stage-and-imputation-event-studies">Two-stage and imputation event studies&lt;/h2>
&lt;p>On a complete panel, fitting unit and date effects on the untreated observations and averaging the residuals of the treated observations by cohort and date gives the cohort-by-date effects of the imputation estimator of Borusyak, Jaravel and Spiess and of Gardner&amp;rsquo;s two-stage estimator with one indicator per treated cell. The preset with not-yet-treated controls and PT-all from the first date fits the same untreated model:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(t) gvar(g) preset(cohort_time_fe) method(reg) baseperiod(universal) controlgroup(notyettreated) ptassumption(all) ptstart(1) bstrap(0) cband(0)
matrix b_preset = e(b)
estat dynamic
matrix b_dynamic = e(b)
quietly regress y i.id i.t if !treated
predict double y0
generate double tau = y - y0 if treated
preserve
collapse (mean) tau if treated, by(g t)
mkmat tau, matrix(b_imputation)
mata: max(abs(st_matrix(&amp;quot;b_preset&amp;quot;) - st_matrix(&amp;quot;b_imputation&amp;quot;)'))
restore
preserve
generate e = t - g
collapse (mean) tau if treated, by(e)
mkmat tau, matrix(b_horizon)
mata: max(abs(st_matrix(&amp;quot;b_dynamic&amp;quot;) - st_matrix(&amp;quot;b_horizon&amp;quot;)'))
restore
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> 4.44089e-16
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> 3.33067e-16
&lt;/code>&lt;/pre>
&lt;p>The first difference compares the six post-treatment cohort-by-date effects, the second the four event-study points; on this complete panel with equal cohort sizes, averaging the treated rows by horizon gives the same cohort weights as &lt;code>estat dynamic&lt;/code>. &lt;code>did_imputation&lt;/code> and &lt;code>did2s&lt;/code> themselves were not run for this guide. The R documentation of &lt;code>cdid&lt;/code> reports the corresponding match with R &lt;code>didimputation&lt;/code> and &lt;code>did2s&lt;/code>, with and without a time-invariant covariate interacted with the dates. With incomplete observations, joint fixed-effects regression and untreated-only imputation can use different information to fit the untreated path, and the weights and inference can differ.&lt;/p>
&lt;h2 id="the-two-date-comparison">The two-date comparison&lt;/h2>
&lt;p>Take a complete panel with one adoption cohort and never-treated controls, keep a baseline and one follow-up date, and code them 1 and 2 with adoption at 2. With no covariates, the effect equals the coefficient on the treated indicator in a regression of the long outcome change, the clean-control comparison used by local-projection DiD at that horizon:&lt;/p>
&lt;pre>&lt;code class="language-stata">preserve
keep if inlist(g, 0, 3) &amp;amp; inlist(t, 2, 5)
replace t = cond(t == 2, 1, 2)
replace g = cond(g == 3, 2, 0)
cdid y, ivar(id) time(t) gvar(g) method(reg) baseperiod(universal) bstrap(0) cband(0)
matrix b = e(b)
scalar att_cdid = b[1, colsof(b)]
bysort id (t): generate double dy = y[2] - y[1]
regress dy i.g if t == 2
display &amp;quot;difference: &amp;quot; %10.3e abs(att_cdid - _b[2.g])
restore
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">difference: 1.998e-15
&lt;/code>&lt;/pre>
&lt;p>With covariates, &lt;code>method(reg)&lt;/code>, &lt;code>method(ipw)&lt;/code> and &lt;code>method(dr)&lt;/code> give the corresponding adjusted comparisons. With more dates, the standard chained estimator combines the supported changes under the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/">chosen parallel-trends assumption&lt;/a>, and &lt;code>cdid_chain&lt;/code> shows which pairs contribute to each effect.&lt;/p>
&lt;h2 id="stepwise-did">Stepwise DiD&lt;/h2>
&lt;p>For cohort 3 and the effect at date 6, Harmon&amp;rsquo;s stepwise estimator adds the comparisons for dates 2 to 3, 3 to 4, 4 to 5 and 5 to 6. Cohort 5 is a control for the first two steps; the later steps use the never-treated units. The loop fits each step with &lt;code>cdid&lt;/code>, takes the post-treatment cell, the last column of &lt;code>e(b)&lt;/code>, and, as a check, computes the same difference in mean changes directly:&lt;/p>
&lt;pre>&lt;code class="language-stata">scalar total_cdid = 0
scalar total_means = 0
forvalues s = 3/6 {
preserve
quietly keep if inlist(t, `s' - 1, `s') &amp;amp; (g == 3 | g == 0 | g &amp;gt; `s')
quietly replace g = cond(g == 3, 2, 0)
quietly replace t = t - `s' + 2
quietly cdid y, ivar(id) time(t) gvar(g) method(reg) baseperiod(universal) bstrap(0) cband(0)
matrix b = e(b)
scalar total_cdid = total_cdid + b[1, colsof(b)]
bysort id (t): generate double dy = y[2] - y[1]
quietly summarize dy if t == 2 &amp;amp; g == 2
scalar m1 = r(mean)
quietly summarize dy if t == 2 &amp;amp; g == 0
scalar total_means = total_means + m1 - r(mean)
restore
}
display &amp;quot;stepwise sum: &amp;quot; total_cdid &amp;quot; difference: &amp;quot; %10.3e abs(total_cdid - total_means)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">stepwise sum: 2.3419796 difference: 8.882e-16
&lt;/code>&lt;/pre>
&lt;p>This reproduces the consecutive-link point estimate. On an incomplete panel, use the target units eligible for the requested horizon and the same observed controls in each step. Uncertainty for the sum must account for the covariance across steps, because units contribute to several comparisons. A single chained fit can also combine longer pairs and additional control pools, and its estimate can then differ from the stepwise sum.&lt;/p>
&lt;h2 id="cohort-chained-did">Cohort-Chained DiD&lt;/h2>
&lt;p>Balla-Elliott and Norwich apply the chaining argument across later-treated control cohorts whose pretreatment windows are short: one untreated cohort supplies the calendar change from dates 1 to 3 and another the change from 3 to 5, so a stacked regression recovers the change from 1 to 5 through the date effects even if no untreated cohort spans it. In &lt;code>cdid&lt;/code>, &lt;code>crosspair&lt;/code> lets the target cohort and the controls supply changes over different pairs, &lt;code>ptassumption(ctrl)&lt;/code> imposes the shared untreated path among eligible controls, and &lt;code>gmmweighting(within)&lt;/code> gives the regression weighting.&lt;/p>
&lt;p>The test &lt;code>tests/stata/test_crosspair_stacked.do&lt;/code> checks this correspondence in Stata. With not-yet-treated controls, &lt;code>baseperiod(universal)&lt;/code>, no covariates and no correction for missing outcomes, the &lt;code>cdid&lt;/code> estimates equal, to within $10^{-11}$ (largest observed difference $2.5 \times 10^{-13}$), the indicator coefficients of stacked target-cohort regressions fitted with &lt;code>areg&lt;/code> (unit fixed effects) on a short-window panel: with complete cohort windows, where cohort fixed effects (&lt;code>regress&lt;/code>) also match; with sampling weights; with monotone attrition within cohorts, where only unit fixed effects match; with dates missing from the calendar; and with one period of anticipation. The same cells are unavailable in both. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining&lt;/a> and the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/short-pretreatment-windows/">worked example with short pretreatment windows&lt;/a>.&lt;/p>
&lt;h2 id="binary-static-switcher-summaries">Binary static switcher summaries&lt;/h2>
&lt;p>For a complete panel with current binary status &lt;code>d&lt;/code> and no covariates, &lt;code>cdid y, ivar(id) time(time) dvar(d) method(reg)&lt;/code> reports a switcher-weighted average of entry and exit effects, expressed in the treated-minus-untreated direction. This corresponds to the WAS estimator of &lt;code>did_multiplegt_stat&lt;/code>. That command is not installed in the environment used for this guide, so the match was not run in Stata here. The R documentation of &lt;code>cdid&lt;/code> reports that, on a complete panel of 384 units and eight dates, R &lt;code>cdid&lt;/code>, R &lt;code>DIDmultiplegtSTAT&lt;/code> and Stata &lt;code>did_multiplegt_stat&lt;/code> give the same average, 1.211393; standard errors depend on the variance normalization. With missing outcomes, &lt;code>cdid&lt;/code> also uses changes over other supported dates in the static model. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/switching/">When treatment can stop and restart&lt;/a>.&lt;/p>
&lt;h2 id="how-software-uses-incomplete-panels">How software uses incomplete panels&lt;/h2>
&lt;p>The chained DiD paper formalizes a missing-trends assumption: the units observed at both dates of a pair must be representative of their cohort with respect to the mean change over that pair, which this guide calls missing trends completely at random. It is weaker than outcomes missing completely at random: response can depend on a persistent difference in levels that cancels in changes, but missingness that depends on characteristics related to outcome growth selects the changes.&lt;/p>
&lt;p>The usual options of the commands above change which observations enter the calculation. A repeated-cross-section DiD (&lt;code>csdid, bal(none)&lt;/code>) compares outcome levels from separate samples at each date and needs those samples to represent the population. A pair-balanced DiD (&lt;code>csdid, bal(pair)&lt;/code>) uses changes of units observed at both dates and needs mean-change representativeness. A linear regression on the available rows (&lt;code>areg&lt;/code>, &lt;code>reghdfe&lt;/code>, &lt;code>jwdid&lt;/code>) links them through its outcome model and relies on the corresponding restrictions on the observed rows. None of these choices fits a model of outcome observation.&lt;/p>
&lt;p>&lt;code>cdid&lt;/code> combines within-unit chaining with an explicit correction for covariate-dependent observation. Under conditional missing trends at random, the observed changes must represent the cohort&amp;rsquo;s mean changes at the same covariate values; the corrections average over the study units, including those with one or both outcomes missing for a pair, and require overlap or prediction support in addition to parallel trends.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>How to handle observation&lt;/th>
&lt;th>Option in &lt;code>cdid&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Missing trends completely at random&lt;/td>
&lt;td>&lt;code>selection(none)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Weight changes by their probability of observation&lt;/td>
&lt;td>&lt;code>selection(conditional_mtar) selmethod(ipw)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Predict the missing changes&lt;/td>
&lt;td>&lt;code>selection(conditional_mtar) selmethod(imputation)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Combine both&lt;/td>
&lt;td>&lt;code>selection(conditional_mtar) selmethod(dr)&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>These choices combine with &lt;code>method(reg)&lt;/code>, &lt;code>method(ipw)&lt;/code> and &lt;code>method(dr)&lt;/code>, in the adoption and switching models and with the cohort-by-date preset. The imputation of missing changes predicts actual changes, which can include treatment effects; this differs from the untreated counterfactual imputed by &lt;code>did_imputation&lt;/code>. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>.&lt;/p>
&lt;h2 id="beyond-these-specifications">Beyond these specifications&lt;/h2>
&lt;p>Dynamic switching with carryover, as in &lt;code>did_multiplegt_dyn&lt;/code>, and nonlinear cohort-by-date models, such as the Poisson option of &lt;code>jwdid&lt;/code>, are not available in &lt;code>cdid&lt;/code>; the &lt;code>dvar()&lt;/code> model targets a static effect. Synthetic control and synthetic DiD (&lt;code>sdid&lt;/code>), and methods built on an estimated event study, such as the sensitivity analysis of Rambachan and Roth, start from different designs or targets.&lt;/p>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Balla-Elliott, D. and Norwich, I. (2025). Cohort-Chained DiD: Long-Run Effects with Limited Pre-Treatment Data. &lt;a href="https://pdfs.dballaelliott.com/ccdid.pdf" target="_blank" rel="noopener">https://pdfs.dballaelliott.com/ccdid.pdf&lt;/a>&lt;/li>
&lt;li>Bellégo, C., Benatia, D. and Dortet-Bernadet, V. (2025). The Chained Difference-in-Differences. &lt;em>Journal of Econometrics&lt;/em>, 248, 105783. &lt;a href="https://doi.org/10.1016/j.jeconom.2024.105783" target="_blank" rel="noopener">https://doi.org/10.1016/j.jeconom.2024.105783&lt;/a>&lt;/li>
&lt;li>Borusyak, K., Jaravel, X. and Spiess, J. (2024). Revisiting Event-Study Designs: Robust and Efficient Estimation. &lt;em>Review of Economic Studies&lt;/em>. &lt;a href="https://doi.org/10.1093/restud/rdae007" target="_blank" rel="noopener">https://doi.org/10.1093/restud/rdae007&lt;/a>&lt;/li>
&lt;li>Callaway, B. and Sant&amp;rsquo;Anna, P. H. C. (2021). Difference-in-Differences with Multiple Time Periods. &lt;em>Journal of Econometrics&lt;/em>, 225(2), 200-230. &lt;a href="https://doi.org/10.1016/j.jeconom.2020.12.001" target="_blank" rel="noopener">https://doi.org/10.1016/j.jeconom.2020.12.001&lt;/a>&lt;/li>
&lt;li>de Chaisemartin, C., D&amp;rsquo;Haultfoeuille, X., Pasquier, F., Sow, D. and Vazquez-Bare, G. (2026). Difference-in-Differences Estimators for Treatments Continuously Distributed at Every Period. arXiv:2201.06898v7. &lt;a href="https://arxiv.org/abs/2201.06898v7" target="_blank" rel="noopener">https://arxiv.org/abs/2201.06898v7&lt;/a>&lt;/li>
&lt;li>Dube, A., Girardi, D., Jordà, Ò. and Taylor, A. M. (2025). A Local Projections Approach to Difference-in-Differences. &lt;em>Journal of Applied Econometrics&lt;/em>. &lt;a href="https://doi.org/10.1002/jae.70000" target="_blank" rel="noopener">https://doi.org/10.1002/jae.70000&lt;/a>&lt;/li>
&lt;li>Gardner, J. (2022). Two-Stage Differences in Differences. arXiv:2207.05943. &lt;a href="https://arxiv.org/abs/2207.05943" target="_blank" rel="noopener">https://arxiv.org/abs/2207.05943&lt;/a>&lt;/li>
&lt;li>Harmon, N. A. (2024). Difference-in-Differences and Efficient Estimation of Treatment Effects. &lt;a href="https://web.econ.ku.dk/nharmon/docs/harmon2022difference.pdf" target="_blank" rel="noopener">https://web.econ.ku.dk/nharmon/docs/harmon2022difference.pdf&lt;/a>&lt;/li>
&lt;li>Sun, L. and Abraham, S. (2021). Estimating Dynamic Treatment Effects in Event Studies with Heterogeneous Treatment Effects. &lt;em>Journal of Econometrics&lt;/em>, 225(2), 175-199. &lt;a href="https://doi.org/10.1016/j.jeconom.2020.09.006" target="_blank" rel="noopener">https://doi.org/10.1016/j.jeconom.2020.09.006&lt;/a>&lt;/li>
&lt;li>Wooldridge, J. M. (2025). Two-Way Fixed Effects, the Two-Way Mundlak Regression, and Difference-in-Differences Estimators. &lt;em>Empirical Economics&lt;/em>. &lt;a href="https://doi.org/10.1007/s00181-025-02807-z" target="_blank" rel="noopener">https://doi.org/10.1007/s00181-025-02807-z&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Estimate treatment effects from incomplete panels</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/</guid><description>&lt;p>Longitudinal datasets are often incomplete: units enter late, leave early, rotate in and out across waves, or miss individual interviews. In multi-period difference-in-differences, how you handle missing outcomes determines both which units contribute to estimation and which causal parameter is identified.&lt;/p>
&lt;p>This article explains the four common panel observation structures, shows how chained difference-in-differences (Bellégo, Benatia and Dortet-Bernadet 2025) spans missing periods without dropping incomplete units or giving up within-unit differencing, and applies &lt;code>cdid&lt;/code> to an incomplete panel.&lt;/p>
&lt;h2 id="four-panel-observation-structures">Four panel observation structures&lt;/h2>
&lt;p>In the diagrams below, each row is a unit and each column is a calendar period $t \in {1, 2, 3, 4}$. An &lt;code>x&lt;/code> marks an observed outcome $Y_{i,t}$ and a &lt;code>.&lt;/code> marks a missing outcome.&lt;/p>
&lt;h3 id="1-balanced-panel">1. Balanced panel&lt;/h3>
&lt;p>Every unit is observed at every calendar period:&lt;/p>
&lt;pre>&lt;code class="language-text">Unit t=1 t=2 t=3 t=4
1 x x x x
2 x x x x
3 x x x x
&lt;/code>&lt;/pre>
&lt;p>For a cohort first treated at $g = 3$ (reference period $t = 2$), every unit has both $Y_{i,2}$ and $Y_{i,4}$, so the direct long difference $Y_{i,4} - Y_{i,2}$ is observed for the entire sample. In a balanced panel, chained and ordinary estimates agree with IPW, no covariates and the same settings (&lt;code>ptassumption(post)&lt;/code>, &lt;code>controlgroup(nevertreated)&lt;/code>, &lt;code>selection(none)&lt;/code>); balance alone does not make other specifications agree (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/get-started/#compare-with-ordinary-did">Get started&lt;/a>).&lt;/p>
&lt;h3 id="2-rotating-panel">2. Rotating panel&lt;/h3>
&lt;p>Each wave interviews a fresh cohort of units for a fixed number of consecutive periods (for example, two consecutive dates) before replacing them:&lt;/p>
&lt;pre>&lt;code class="language-text">Unit t=1 t=2 t=3 t=4
1 x x . .
2 . x x .
3 . . x x
&lt;/code>&lt;/pre>
&lt;p>Here, &lt;strong>no unit&lt;/strong> is observed at all four periods, and &lt;strong>no unit&lt;/strong> is observed at both $t = 2$ and $t = 4$:&lt;/p>
&lt;ul>
&lt;li>&lt;code>mode(ordinary)&lt;/code> with default balanced-panel handling (&lt;code>allowunbalanced(false)&lt;/code>) drops every unit and cannot run.&lt;/li>
&lt;li>Even a two-period direct comparison between $t = 2$ and $t = 4$ finds zero units with both $Y_{i,2}$ and $Y_{i,4}$.&lt;/li>
&lt;li>However, adjacent changes $Y_{i,2} - Y_{i,1}$, $Y_{i,3} - Y_{i,2}$, and $Y_{i,4} - Y_{i,3}$ are all observed within units. By chaining the $2 \to 3$ and $3 \to 4$ within-unit changes, &lt;code>mode(chained)&lt;/code> recovers $\text{ATT}(g=3, t=4)$ relative to reference period $t = 2$.&lt;/li>
&lt;/ul>
&lt;h3 id="3-attrition-and-late-entry">3. Attrition and late entry&lt;/h3>
&lt;p>Some units leave the sample permanently after a date, while others enter after period 1:&lt;/p>
&lt;pre>&lt;code class="language-text">Unit t=1 t=2 t=3 t=4
1 x x x x
2 x x x .
3 . x x x
&lt;/code>&lt;/pre>
&lt;p>Every ordered pair $(s, t)$ has some units observed at both endpoints, alongside additional units observed on intermediate steps. Chained GMM uses &lt;strong>both&lt;/strong> the direct long differences $(2, 4)$ from units 1 and 3 &lt;strong>and&lt;/strong> the chained two-step path $(2, 3) + (3, 4)$ that incorporates unit 2 on $(2, 3)$.&lt;/p>
&lt;h3 id="4-general-incomplete-panel">4. General incomplete panel&lt;/h3>
&lt;p>Units miss sporadic dates, some units are observed only once (singletons, $B \setminus A$), and some units in the study population unit table $F$ have no observed outcomes at all ($F \setminus B$):&lt;/p>
&lt;pre>&lt;code class="language-text">Unit t=1 t=2 t=3 t=4 Membership
1 x . x x A (&amp;gt;= 2 dates)
2 . x x . A (&amp;gt;= 2 dates)
3 x x . x A (&amp;gt;= 2 dates)
4 . x . . B \ A (singleton: 1 date)
5 . . . . F \ B (unit table only: 0 dates)
&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>Units 1, 2, and 3 belong to $A$, the units observed at two or more dates, and supply within-unit changes $\Delta_{s,t} Y_i = Y_{i,t} - Y_{i,s}$ on the specific date pairs where both endpoints are observed.&lt;/li>
&lt;li>Unit 4 belongs to $B \setminus A$: it cannot supply any within-unit change $\Delta_{s,t} Y_i$, because differencing requires two observed dates.&lt;/li>
&lt;li>Unit 5 belongs to $F \setminus B$: it appears in the unit table supplied with &lt;code>frame()&lt;/code> with baseline covariates and cohort membership, but has no observed outcomes.&lt;/li>
&lt;li>In &lt;code>mode(chained)&lt;/code>, units 4 and 5 are &lt;strong>never discarded from the target population $F$&lt;/strong>: they remain in the cohort shares, covariate distributions on $F$, observation-probability models on $F$, cluster sums, and influence functions, which have one row for each of the $N_F$ units (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/#the-study-population">Handling missing outcomes&lt;/a>).&lt;/li>
&lt;/ul>
&lt;h2 id="how-chaining-works-telescoping-and-earlier-dates">How chaining works: telescoping and earlier dates&lt;/h2>
&lt;p>Consider a cohort first treated at $g = 3$ with &lt;code>anticipation(0)&lt;/code>, so its reference period is $t = 2$, and suppose we want to identify $\text{ATT}(3, 4) = E[Y_4(3) - Y_4(0) \mid G = 3]$.&lt;/p>
&lt;h3 id="forward-telescoping-across-intermediate-dates">Forward telescoping across intermediate dates&lt;/h3>
&lt;p>In the fixed cohort population $G = k$, expectations are linear:&lt;/p>
&lt;p>$$E[Y_4 - Y_2 \mid G = k] = E[Y_3 - Y_2 \mid G = k] + E[Y_4 - Y_3 \mid G = k]$$&lt;/p>
&lt;p>Let $\Delta_{s,t}^{\text{DiD}}$ denote the adjusted difference-in-differences comparison between cohort $g = 3$ and the control group over pair $(s, t)$. Under conditional parallel trends from period 2 onward (&lt;code>ptassumption(post)&lt;/code>) and representative pair changes within each cohort (&lt;code>selection(none)&lt;/code>, or after missing-outcome adjustment under &lt;code>selection(conditional_mtar)&lt;/code>):&lt;/p>
&lt;ul>
&lt;li>$\Delta_{2,3}^{\text{DiD}}$ identifies $\text{ATT}(3, 3)$,&lt;/li>
&lt;li>$\Delta_{3,4}^{\text{DiD}}$ identifies $\text{ATT}(3, 4) - \text{ATT}(3, 3)$,&lt;/li>
&lt;li>$\Delta_{2,4}^{\text{DiD}}$ directly identifies $\text{ATT}(3, 4)$.&lt;/li>
&lt;/ul>
&lt;p>Summing the two adjacent steps $\Delta_{2,3}^{\text{DiD}} + \Delta_{3,4}^{\text{DiD}}$ cancels $\text{ATT}(3, 3)$ and identifies $\text{ATT}(3, 4)$ even if no unit is observed at both $t = 2$ and $t = 4$. When both the direct pair $(2, 4)$ and the adjacent pairs $(2, 3)$ and $(3, 4)$ are observed, &lt;code>cdid&lt;/code> includes all three in an overidentified GMM system and weights them optimally using their joint influence-function covariance (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/">GMM weighting and covariance regularization&lt;/a>).&lt;/p>
&lt;h3 id="cancellation-through-dates-before-the-reference-period">Cancellation through dates before the reference period&lt;/h3>
&lt;p>Under &lt;code>ptassumption(post)&lt;/code>, conditional parallel trends are only assumed from the reference period $g - 1 - \text{anticipation}$ onward ($t = 2$ for $g = 3$). Even so, comparisons starting at an earlier date $t = 1$ remain informative whenever a cohort has observed pairs $(1, 2)$ and $(1, 3)$:&lt;/p>
&lt;p>$$E[Y_3 - Y_1 \mid G = k] - E[Y_2 - Y_1 \mid G = k] = E[Y_3 - Y_2 \mid G = k]$$&lt;/p>
&lt;p>In the GMM design matrix $A$, the comparison $\Delta_{1,2}^{\text{DiD}}$ loads on the unrestricted pre-reference differential $\delta_{3, 1 \to 2}$, while $\Delta_{1,3}^{\text{DiD}}$ loads on $\delta_{3, 1 \to 2} + \text{ATT}(3, 3)$. Differencing the two moments eliminates $\delta_{3, 1 \to 2}$ without assuming parallel trends between $t = 1$ and $t = 2$ (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/#comparisons-through-earlier-dates-under-ptassumptionpost">Parallel trends&lt;/a>).&lt;/p>
&lt;blockquote>
&lt;p>[!IMPORTANT]
&lt;strong>Population identity versus realized sample means:&lt;/strong> Telescoping ($E[Y_4 - Y_2] = E[Y_3 - Y_2] + E[Y_4 - Y_3]$) and the cancellation through earlier dates hold for &lt;strong>population expectations&lt;/strong> over the same cohort $G = k$ in $F$. When different subsets of units are observed on $(2, 3)$, $(3, 4)$, and $(2, 4)$, the realized sample means on those subsets will generally differ in a finite draw even when each pair is representative in mean change.&lt;/p>
&lt;/blockquote>
&lt;h2 id="comparing-modechained-and-modeordinary-in-stata">Comparing &lt;code>mode(chained)&lt;/code> and &lt;code>mode(ordinary)&lt;/code> in Stata&lt;/h2>
&lt;p>In incomplete panels, ordinary mode by default keeps only the units observed in every period. With &lt;code>allowunbalanced&lt;/code>, it uses the repeated cross-section estimators, with standard errors clustered by unit. The two approaches rest on different assumptions about the population and the sampling. Chained mode combines the changes of all units over the study population, under its assumption that the observed changes are representative. Using more units or obtaining a smaller standard error does not by itself show that an approach is valid.&lt;/p>
&lt;p>With the data of the hands-on do-file in memory, the following specifications without covariates compare the three approaches. They illustrate the syntax; the data do not follow the observation patterns shown above:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(period) gvar(first_treat) ///
method(ipw) frame(cdid_pop) bstrap(0) cband(0)
cdid y, ivar(id) time(period) gvar(first_treat) ///
mode(ordinary) method(ipw) bstrap(0) cband(0)
cdid y, ivar(id) time(period) gvar(first_treat) ///
mode(ordinary) allowunbalanced method(ipw) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 3 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/">Moving from did and csdid&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/identification/">Identify effects when the observed units change composition&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Familiar difference-in-differences models, with incomplete panels</title><link>https://www.davidbenatia.com/tools/cdid/stata/comparisons/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/comparisons/</guid><description>&lt;p>A survey follows households for three years. Some households are interviewed in years 1 and 2, others in years 2 and 3, and few in both years 1 and 3. The two shorter changes still say something about the longer interval. Chained difference-in-differences uses those changes to estimate treatment effects when the observation patterns and the parallel trends assumptions support the comparisons. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/identification/">Worked example&lt;/a> · &lt;a href="https://doi.org/10.1016/j.jeconom.2024.105783" target="_blank" rel="noopener">Chained DiD paper&lt;/a>&lt;/p>
&lt;p>&lt;code>cdid&lt;/code> relates several familiar estimators to one Stata command. Its ordinary mode computes the Callaway and Sant&amp;rsquo;Anna estimator with &lt;code>csdid&lt;/code>. Its cohort-by-date preset fits the linear regression with unit and date fixed effects and one effect per treated cohort and date, the specification of Wooldridge&amp;rsquo;s extended two-way fixed effects (&lt;code>jwdid&lt;/code>, &lt;code>xthdidregress twfe&lt;/code>); with never-treated controls it is also the saturated regression of Sun and Abraham (&lt;code>eventstudyinteract&lt;/code>), and with not-yet-treated controls and a common untreated path it gives, on a complete panel, the cohort-by-date effects of the imputation and two-stage estimators (&lt;code>did_imputation&lt;/code>, &lt;code>did2s&lt;/code>). Consecutive two-date fits give Harmon&amp;rsquo;s stepwise DiD, cross-pair chaining gives the stacked regressions of Cohort-Chained DiD, and the &lt;code>dvar()&lt;/code> model gives static binary switcher effects (&lt;code>did_multiplegt_stat&lt;/code>). &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/">Matched specifications and the checks run for this guide&lt;/a>&lt;/p>
&lt;h2 id="what-missing-trends-at-random-means">What missing trends at random means&lt;/h2>
&lt;p>Taking changes within households removes persistent differences in their outcome levels. The chained DiD paper asks whether the households observed at both ends of a pair are representative of their cohort with respect to the &lt;strong>mean change&lt;/strong> over that interval. This guide calls that baseline missing trends completely at random. It is weaker than outcomes missing completely at random: households with persistently low income can respond less often while their income changes remain representative. If response depends on a characteristic that also predicts income growth, the observed changes can be selective. &lt;a href="https://doi.org/10.1016/j.jeconom.2024.105783" target="_blank" rel="noopener">Chained DiD paper, Assumptions 2 and 6&lt;/a>&lt;/p>
&lt;p>Repeated cross-section DiD compares levels in the samples observed at different dates; pair-balanced DiD compares changes for the units observed at both dates of each comparison. Each needs its own representativeness assumption. Chaining can use additional observed changes, and the observation correction addresses selection into those changes. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/#how-software-uses-incomplete-panels">How the commands use incomplete panels&lt;/a>&lt;/p>
&lt;p>When representativeness holds &lt;strong>conditional on measured characteristics&lt;/strong>, &lt;code>cdid&lt;/code> can weight changes by their probability of observation, predict the missing changes, or combine both. This choice is separate from the treatment adjustment by outcome regression, inverse probability weighting or doubly robust estimation; for example, the cohort-by-date preset can be combined with doubly robust treatment adjustment and the augmented correction for missing outcomes. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a> · &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cohort-time-fe/#adjust-for-selective-observation">Cohort-by-date example&lt;/a>&lt;/p>
&lt;p>The &lt;code>dvar()&lt;/code> model is for settings where past treatment has no lingering effect. Dynamic treatment histories and nonlinear cohort-by-date models are outside the current package. To try the supported specifications, start with the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/">matched commands&lt;/a>, and use &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/investigate-missingness/">the data guide&lt;/a> to see which changes your panel supplies.&lt;/p>
&lt;p>See the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/#references">references for the matched methods&lt;/a>.&lt;/p>
&lt;hr>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Get started: estimate effects in an incomplete panel</title><link>https://www.davidbenatia.com/tools/cdid/stata/get-started/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/get-started/</guid><description>&lt;p>This page simulates a staggered panel in which one outcome in five is missing, estimates the group-time effects in chained mode and then uses the main postestimation commands: replay, the four &lt;code>estat&lt;/code> aggregations, &lt;code>cdid_plot&lt;/code>, &lt;code>cdid_export&lt;/code>, and saved results with &lt;code>cdid_load&lt;/code>. The output was produced by &lt;code>cdid&lt;/code> 1.0.0.0 in Stata 19.5 by running the commands of this page in order. It is one simulated sample and says nothing about coverage in repeated samples.&lt;/p>
&lt;h2 id="the-question">The question&lt;/h2>
&lt;p>About 60 percent of 600 units start a treatment in 2004 or 2006 and stay treated; the others are never treated. Outcomes are observed from 2001 to 2008, but each outcome is missing with probability 0.2, independently of everything else. What is the average effect of the treatment on each cohort at each date, and how do the effects summarize?&lt;/p>
&lt;h2 id="prepare-the-panel">Prepare the panel&lt;/h2>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261116
set obs 600
generate id = _n
generate G = cond(runiform() &amp;lt; .4, 0, cond(runiform() &amp;lt; .5, 2004, 2006))
generate x = rnormal()
expand 8
bysort id: generate year = 2000 + _n
generate y = x + .2*(year - 2000) + (G &amp;gt; 0 &amp;amp; year &amp;gt;= G)*(1 + .25*(year - G)) + rnormal()
replace y = . if runiform() &amp;lt; .2
&lt;/code>&lt;/pre>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Variable&lt;/th>
&lt;th>Meaning&lt;/th>
&lt;th>Option&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>y&lt;/code>&lt;/td>
&lt;td>outcome, missing for about one row in five&lt;/td>
&lt;td>&lt;code>depvar&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>year&lt;/code>&lt;/td>
&lt;td>date, 2001 to 2008&lt;/td>
&lt;td>&lt;code>time()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>id&lt;/code>&lt;/td>
&lt;td>unit identifier&lt;/td>
&lt;td>&lt;code>ivar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>G&lt;/code>&lt;/td>
&lt;td>first treatment date, 0 for units never treated&lt;/td>
&lt;td>&lt;code>gvar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>x&lt;/code>&lt;/td>
&lt;td>covariate, constant within unit&lt;/td>
&lt;td>&lt;code>indepvars&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Every unit keeps a row at every date, with &lt;code>y&lt;/code> missing where the outcome is not observed. The units in the data are the study population, so no unit table (&lt;code>frame()&lt;/code>) is needed. The cohort sizes and the number of observed outcomes per unit:&lt;/p>
&lt;pre>&lt;code class="language-stata">tabulate G if year == 2001
egen n_obs = total(!missing(y)), by(id)
tabulate n_obs if year == 2001
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> G | Freq. Percent Cum.
------------+-----------------------------------
0 | 236 39.33 39.33
2004 | 168 28.00 67.33
2006 | 196 32.67 100.00
------------+-----------------------------------
Total | 600 100.00
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text"> n_obs | Freq. Percent Cum.
------------+-----------------------------------
3 | 3 0.50 0.50
4 | 30 5.00 5.50
5 | 87 14.50 20.00
6 | 169 28.17 48.17
7 | 213 35.50 83.67
8 | 98 16.33 100.00
------------+-----------------------------------
Total | 600 100.00
&lt;/code>&lt;/pre>
&lt;p>Only 98 units are observed at all eight dates. Every unit is observed at least three times, so every unit contributes changes.&lt;/p>
&lt;p>The simulated effect is $1 + 0.25,(t - g)$ from the treatment date onward and zero before; the untreated trend, $0.2$ per year, is shared by all units:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Quantity&lt;/th>
&lt;th>Simulated truth&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Cells before treatment&lt;/td>
&lt;td>0&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ATT(2004, 2004), ATT(2004, 2005), &amp;hellip;, ATT(2004, 2008)&lt;/td>
&lt;td>1.00, 1.25, 1.50, 1.75, 2.00&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ATT(2006, 2006), ATT(2006, 2007), ATT(2006, 2008)&lt;/td>
&lt;td>1.00, 1.25, 1.50&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="assumptions-for-this-example">Assumptions for this example&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Comparison group.&lt;/strong> Units never treated (&lt;code>controlgroup(nevertreated)&lt;/code>, the default).&lt;/li>
&lt;li>&lt;strong>No anticipation.&lt;/strong> Units do not react before their treatment date (&lt;code>anticipation(0)&lt;/code>). The reference date of cohort 2004 is 2003, that of cohort 2006 is 2005.&lt;/li>
&lt;li>&lt;strong>Parallel trends from the reference date (PT-post).&lt;/strong> Without treatment, the mean outcome of each cohort would have changed from its reference date onward like that of the units never treated. The simulation satisfies this by construction.&lt;/li>
&lt;li>&lt;strong>Missing outcomes.&lt;/strong> Under &lt;code>selection(none)&lt;/code>, the default, the units observed at both dates of a comparison must represent their cohort&amp;rsquo;s mean change over that pair. Here outcomes are missing completely at random, which is sufficient.&lt;/li>
&lt;li>&lt;strong>Overlap.&lt;/strong> Treatment does not depend on &lt;code>x&lt;/code>, so every cohort overlaps with the controls.&lt;/li>
&lt;/ul>
&lt;h2 id="estimate-the-effects">Estimate the effects&lt;/h2>
&lt;pre>&lt;code class="language-stata">cdid y x, ivar(id) time(year) gvar(G)
&lt;/code>&lt;/pre>
&lt;p>The command uses the defaults: doubly robust treatment adjustment (&lt;code>method(dr)&lt;/code>) with &lt;code>x&lt;/code> as covariate, never-treated controls, PT-post, a varying base period for the pretreatment cells, and 1000 multiplier-bootstrap draws with a 95% simultaneous band (&lt;code>bstrap(1) cband(1) biters(1000) level(95)&lt;/code>). The draws use Stata&amp;rsquo;s random-number stream, so the &lt;code>set seed&lt;/code> above makes them reproducible.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Value in this example&lt;/th>
&lt;th>Definition&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>ivar()&lt;/code>, &lt;code>time()&lt;/code>, &lt;code>gvar()&lt;/code>&lt;/td>
&lt;td>&lt;code>id&lt;/code>, &lt;code>year&lt;/code>, &lt;code>G&lt;/code>&lt;/td>
&lt;td>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/#data-timing-and-comparison-group">Data, timing and comparison group&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>controlgroup()&lt;/code>&lt;/td>
&lt;td>&lt;code>nevertreated&lt;/code> (default)&lt;/td>
&lt;td>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/#data-timing-and-comparison-group">Data, timing and comparison group&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>method()&lt;/code>&lt;/td>
&lt;td>&lt;code>dr&lt;/code> (default)&lt;/td>
&lt;td>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/#treatment-adjustment">Treatment adjustment&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ptassumption()&lt;/code>, &lt;code>baseperiod()&lt;/code>&lt;/td>
&lt;td>&lt;code>post&lt;/code>, &lt;code>varying&lt;/code> (defaults)&lt;/td>
&lt;td>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/#parallel-trends-and-reporting">Parallel trends and reporting&lt;/a>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>bstrap()&lt;/code>, &lt;code>cband()&lt;/code>, &lt;code>biters()&lt;/code>, &lt;code>level()&lt;/code>&lt;/td>
&lt;td>defaults&lt;/td>
&lt;td>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/#inference">Inference&lt;/a>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="read-the-result">Read the result&lt;/h2>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 600
Method: doubly robust (dr) Number of cells = 14
GMM weighting: optimal
Control group: never treated; base period: varying
------------------------------------------------------------------------------
Group Time Role ATT Std. err. [95% simult. band]
------------------------------------------------------------------------------
2004 2002 pre .06465903 .1813182 -.4339139 .5632319
2004 2003 pre -.1160236 .1925284 -.6454215 .4133743
2004 2004 post .8007932 .1632064 .3520225 1.249564
2004 2005 post 1.292404 .167314 .8323385 1.752469
2004 2006 post 1.36689 .1629828 .9187344 1.815046
2004 2007 post 1.656024 .1620924 1.210316 2.101731
2004 2008 post 1.986083 .1628001 1.53843 2.433736
2006 2002 pre -.0010518 .174538 -.4809813 .4788777
2006 2003 pre -.2412746 .1938725 -.7743684 .2918193
2006 2004 pre -.2701289 .1642154 -.7216741 .1814164
2006 2005 pre .3776257 .1680423 -.08444252 .8396939
2006 2006 post .7959092 .1510761 .3804932 1.211325
2006 2007 post 1.096312 .1698427 .6292929 1.56333
2006 2008 post 1.734893 .1738765 1.256783 2.213004
------------------------------------------------------------------------------
Std. err.: multiplier bootstrap (interquartile range of 1000 draws); simultaneous 95% band over
the available cells. e(V) holds the analytic covariance.
Pretrend Wald test (pre-treatment cells): chi2(6) = 9.89, Prob &amp;gt; chi2 = 0.1296
&lt;/code>&lt;/pre>
&lt;p>Each row is a cell: the cohort (&lt;code>Group&lt;/code>), the date (&lt;code>Time&lt;/code>) and its role. &lt;code>post&lt;/code> cells are the treatment effects ATT(g,t). &lt;code>pre&lt;/code> cells compare each pretreatment date with the preceding date, because the base period is varying; they describe the trends of the cohort and its controls before treatment. &lt;code>Lower&lt;/code> and &lt;code>Upper&lt;/code> bound the 95% simultaneous band over the reported cells. The last line tests jointly that the pretreatment cells are zero; failure to reject does not establish parallel trends.&lt;/p>
&lt;p>Typing &lt;code>cdid&lt;/code> alone redisplays the current results. The table reports the available cells; &lt;code>cdid_export, type(cells)&lt;/code> writes every cell with its availability and, for an unavailable cell, the reason. &lt;code>e(b)&lt;/code> holds the available estimates and &lt;code>e(coef_map)&lt;/code> the cell of each one. &lt;code>e(V)&lt;/code> is the analytical covariance, while &lt;code>e(se)&lt;/code> and &lt;code>e(ci)&lt;/code> hold the reported bootstrap standard errors and band; &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/#uncertainty">Results&lt;/a> explains the difference.&lt;/p>
&lt;h2 id="aggregate-the-effects">Aggregate the effects&lt;/h2>
&lt;p>&lt;code>estat&lt;/code> summarizes the stored cells without refitting. It replaces the results in &lt;code>e()&lt;/code> with the aggregation, so store the fit first if you want to return to it:&lt;/p>
&lt;pre>&lt;code class="language-stata">estimates store fit
estat simple
estat group
estat calendar
estat dynamic
&lt;/code>&lt;/pre>
&lt;p>&lt;code>estat simple&lt;/code> averages all post-treatment cells, weighting each cohort by its share of the treated units:&lt;/p>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 600
Method: doubly robust (dr)
GMM weighting: optimal
Control group: never treated; base period: varying
Aggregation: simple (average effect over all post-treatment cells)
------------------------------------------------------------------------------
ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
Overall 1.333391 .08372642 1.169291 1.497492
------------------------------------------------------------------------------
Std. err.: multiplier bootstrap (interquartile range of 1000 draws); pointwise 95% intervals. e(V)
holds the analytic covariance.
Pretrend Wald test (pre-treatment cells): chi2(6) = 9.89, Prob &amp;gt; chi2 = 0.1296
&lt;/code>&lt;/pre>
&lt;p>&lt;code>estat dynamic&lt;/code> averages the cells by time since adoption, an event study:&lt;/p>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 600
Method: doubly robust (dr) Number of event times = 9
GMM weighting: optimal
Control group: never treated; base period: varying
Aggregation: dynamic
------------------------------------------------------------------------------
Event time ATT Std. err. [95% simult. band]
------------------------------------------------------------------------------
Overall 1.438426 .08863714 1.264701 1.612152
------------------------------------------------------------------------------
-4 -.0010518 .1718845 -.472572 .4704684
-3 -.2412746 .1740801 -.7188177 .2362686
-2 -.1156114 .1215034 -.4489241 .2177013
-1 .1497876 .1288909 -.203791 .5033661
0 .7981633 .1048659 .5104911 1.085836
1 1.186816 .1061597 .8955944 1.478037
2 1.565046 .1112072 1.259978 1.870114
3 1.656024 .1641359 1.20576 2.106288
4 1.986083 .168826 1.522953 2.449213
------------------------------------------------------------------------------
Std. err.: multiplier bootstrap (interquartile range of 1000 draws); simultaneous 95% band over
the available estimates. e(V) holds the analytic covariance.
The overall summary uses a pointwise interval.
Pretrend Wald test (pre-treatment cells): chi2(6) = 9.89, Prob &amp;gt; chi2 = 0.1296
&lt;/code>&lt;/pre>
&lt;p>&lt;code>estat group&lt;/code> reports one average per cohort and &lt;code>estat calendar&lt;/code> one per date. Each aggregation also reports an overall estimate with a pointwise interval, while the band covers the bins of that aggregation. Cohort shares are computed over the study population, including units with missing outcomes. Each call draws new bootstrap multipliers, so the standard errors of one aggregation vary slightly from one call to the next; the point estimates do not.&lt;/p>
&lt;h2 id="plot-the-effects">Plot the effects&lt;/h2>
&lt;pre>&lt;code class="language-stata">cdid_plot
estimates restore fit
cdid_plot
&lt;/code>&lt;/pre>
&lt;p>The first &lt;code>cdid_plot&lt;/code> draws the current aggregation, the event study; after &lt;code>estimates restore fit&lt;/code>, the second draws the group-time cells, one panel per cohort. Pretreatment and post-treatment estimates have different colors.&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://www.davidbenatia.com/tools/cdid/assets/stata/docs/assets/get-started-dynamic.png" alt="Event study with a 95% simultaneous band" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;p>
&lt;figure >
&lt;div class="d-flex justify-content-center">
&lt;div class="w-100" >&lt;img src="https://www.davidbenatia.com/tools/cdid/assets/stata/docs/assets/get-started-cells.png" alt="Group-time effects by cohort with a 95% simultaneous band" loading="lazy" data-zoomable />&lt;/div>
&lt;/div>&lt;/figure>
&lt;/p>
&lt;h2 id="export-tables-and-save-results">Export tables and save results&lt;/h2>
&lt;pre>&lt;code class="language-stata">estimates restore fit
cdid_export using gs_cells, type(cells) replace
tempfile saved
cdid y x, ivar(id) time(year) gvar(G) saving(`saved')
cdid_load using `saved'
estat dynamic
&lt;/code>&lt;/pre>
&lt;p>&lt;code>cdid_export&lt;/code> writes the cells to &lt;code>gs_cells.dta&lt;/code>, one observation per cell; &lt;code>type(aggregate)&lt;/code>, &lt;code>type(units)&lt;/code>, &lt;code>type(influence)&lt;/code> and &lt;code>type(summary)&lt;/code> write the other tables. &lt;code>saving()&lt;/code> writes the complete results, and &lt;code>cdid_load&lt;/code> restores them without the data, so that &lt;code>estat&lt;/code>, &lt;code>cdid_plot&lt;/code> and &lt;code>cdid_export&lt;/code> can be used later. The refit above draws new bootstrap multipliers, so its standard errors differ slightly from the first fit; its point estimates are identical. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/user-results/">Working with results&lt;/a> describes the files.&lt;/p>
&lt;h2 id="compare-with-ordinary-did">Compare with ordinary DiD&lt;/h2>
&lt;pre>&lt;code class="language-stata">cdid y x, ivar(id) time(year) gvar(G) mode(ordinary) bstrap(0) cband(0)
cdid y x, ivar(id) time(year) gvar(G) mode(ordinary) allowunbalanced bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">note: 502 unit(s) not observed in every period were dropped; specify allowunbalanced to keep them
Difference-in-differences (ordinary mode) Number of units = 98
Method: doubly robust (dr) Number of cells = 14
------------------------------------------------------------------------------
Group Time ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
2004 2002 .2403625 .3337969 -.4138674 .8945923
2004 2003 .2293042 .3689096 -.4937454 .9523538
2004 2004 1.222235 .3302933 .5748716 1.869598
2004 2005 1.389771 .3806285 .6437523 2.135789
2004 2006 1.423924 .3667167 .7051727 2.142676
2004 2007 1.663563 .3656605 .9468816 2.380244
2004 2008 1.820988 .3537814 1.127589 2.514386
2006 2002 .2990589 .3124318 -.3132962 .9114141
2006 2003 -.1732519 .2895376 -.7407351 .3942313
2006 2004 .1805558 .319025 -.4447217 .8058334
2006 2005 -.05849817 .3982952 -.8391425 .7221462
2006 2006 .8286732 .3198087 .2018598 1.455487
2006 2007 .8867376 .3901815 .1219959 1.651479
2006 2008 1.312276 .3725548 .5820823 2.04247
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
Pretrend Wald test (pre-treatment cells): chi2(6) = 2.96, Prob &amp;gt; chi2 = 0.8143
&lt;/code>&lt;/pre>
&lt;p>By default, ordinary mode keeps only the 98 units observed at every date, so its estimates are much less precise here. With &lt;code>allowunbalanced&lt;/code>, it keeps all units and compares outcome levels with repeated cross-section estimators:&lt;/p>
&lt;pre>&lt;code class="language-text">Difference-in-differences (ordinary mode) Number of units = 600
Method: doubly robust (dr) Number of cells = 14
------------------------------------------------------------------------------
Group Time ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
2004 2002 .1079136 .1550416 -.1959623 .4117896
2004 2003 -.02572416 .1568961 -.3332349 .2817865
2004 2004 .6586376 .1565251 .3518539 .9654212
2004 2005 1.273853 .1623038 .9557433 1.591963
2004 2006 1.339856 .1559586 1.034182 1.645529
2004 2007 1.672386 .1633037 1.352317 1.992455
2004 2008 1.969221 .1548683 1.665685 2.272758
2006 2002 .08135314 .1607196 -.2336515 .3963578
2006 2003 -.1895846 .157225 -.49774 .1185707
2006 2004 -.2084874 .1544496 -.5112031 .0942283
2006 2005 .2765159 .1593149 -.03573552 .5887672
2006 2006 .8229347 .1421898 .5442477 1.101622
2006 2007 1.108006 .1632059 .7881285 1.427884
2006 2008 1.738089 .1604108 1.42369 2.052489
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
Pretrend Wald test (pre-treatment cells): chi2(6) = 8.29, Prob &amp;gt; chi2 = 0.2176
&lt;/code>&lt;/pre>
&lt;p>Because outcomes are missing completely at random in this simulation, both chained and level comparisons are valid here, and the estimates are close. They need not be when observation depends on persistent differences between units; &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/">Moving from did and csdid&lt;/a> explains when they should agree.&lt;/p>
&lt;h2 id="next-steps">Next steps&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/">Moving from did and csdid&lt;/a> relates chained and ordinary estimation.&lt;/li>
&lt;li>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/">Prepare your panel and unit table&lt;/a> lists the input requirements.&lt;/li>
&lt;li>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a> covers outcomes whose observation depends on covariates.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 1 of 22&lt;/strong> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/">Moving from did and csdid&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>GMM weighting and covariance regularization</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/</guid><description>&lt;p>This page describes the moment conditions of chained estimation, how the comparisons are weighted, and how their covariance is regularized.&lt;/p>
&lt;h2 id="moment-conditions-and-the-quadratic-objective">Moment conditions and the quadratic objective&lt;/h2>
&lt;p>Let $\hat{d}$ denote the $M \times 1$ vector of two-period comparison estimates used by &lt;code>cdid&lt;/code>. Each entry of $\hat{d}$ compares outcome changes between an ordered pair of dates for a target cohort with its control group (never-treated or not-yet-treated units, including comparisons that use the same pair of dates again with another control group), constructed using the selected treatment adjustment (&lt;code>method()&lt;/code>) and missing-outcome correction (&lt;code>selection()&lt;/code> and &lt;code>selmethod()&lt;/code>).&lt;/p>
&lt;p>Let $\theta$ denote the GMM model parameters: post-treatment effects and any pre-period trend differentials left free by the chosen parallel-trends model. PT-all restricts the differentials before the reference period; these model parameters are distinct from the direct, unrestricted pre-period cells reported for the pretrend test. Let $d$ denote the vector of population comparison means and $A$ the known $M \times p$ design mapping $\theta$ to them. Under sufficient parallel-trends, observation, overlap and model conditions, with the required regularity,&lt;/p>
&lt;p>$$
d = A\theta, \qquad \hat{d} \xrightarrow{p} d
$$&lt;/p>
&lt;p>This is a population moment restriction and a large-sample statement, not a claim that nuisance-adjusted sample comparisons are unbiased. Given a symmetric positive-semidefinite $M \times M$ weighting matrix $W$, the chained GMM estimator minimizes the quadratic form&lt;/p>
&lt;p>$$
Q_W(\theta) = (\hat{d} - A\theta)' W (\hat{d} - A\theta),
$$&lt;/p>
&lt;p>and recovers each supported post-treatment target $\tau_j = c_j'\theta$ as a linear contrast of the fitted parameter vector $\hat{\theta}$.&lt;/p>
&lt;p>Several properties follow directly from this formulation:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Sufficient conditions for recovery.&lt;/strong> Validity of every comparison used under the assumed parallel-trends, observation-selection, overlap and nuisance-model conditions, identification of $c_j$ from the row space of $A$, and standard GMM regularity are sufficient for consistency. They are not necessary in every special case: misspecification can cancel in a target contrast. Such cancellation is not a general robustness guarantee.&lt;/li>
&lt;li>&lt;strong>What $W$ changes when moments are valid.&lt;/strong> When the full moment conditions hold and $W$ converges in probability to a positive-definite limit $W_0$ that preserves the rank of $A$, changing $W$ can change the linear combination of overidentifying comparisons used to reconstruct $\tau_j$ and its asymptotic and finite-sample precision. It does not change the population target.&lt;/li>
&lt;li>&lt;strong>No finite-sample unbiasedness or arbitrary-$W$ guarantee.&lt;/strong> Feasible two-step GMM estimates $W$ from the same sample used to form $\hat{d}$. Inserting a data-dependent weighting matrix does not establish exact finite-sample unbiasedness, and asymptotic validity does not hold for arbitrary unstable or data-adaptive choices of $W$.&lt;/li>
&lt;li>&lt;strong>Sensitivity to incompatible moments.&lt;/strong> If the population limits of the comparisons used cannot all be represented by one $A\theta$ (for example after invalid trend or observation restrictions), the moments are incompatible. Misspecification alone need not imply incompatibility or bias in every contrast. Under the relevant convergence conditions, the limiting criterion defines a weighted pseudo-target that generally depends on the limiting weights.&lt;/li>
&lt;li>&lt;strong>Moment-covariance ridge is not a parameter penalty.&lt;/strong> When the estimated moment covariance is regularized before inversion to form $W$, the positive ridge is added to the &lt;em>moment covariance matrix&lt;/em>, not to $A&amp;rsquo;WA$ and not as an $L_2$ penalty on $\theta$. It imposes no shrinkage target on ATT and supplies no identifying restrictions on $\theta$. A particular estimate can nevertheless move closer to or farther from zero when its comparison weights change.&lt;/li>
&lt;/ul>
&lt;h2 id="weighting-and-covariance-options">Weighting and covariance options&lt;/h2>
&lt;p>&lt;code>gmmweighting(optimal)&lt;/code> is the default feasible two-step weighting; &lt;code>two_step&lt;/code> is a synonym. &lt;code>gmmweighting(identity)&lt;/code> minimizes the unweighted criterion over all comparisons. &lt;code>gmmweighting(within)&lt;/code> weights by the inverse of an analytical covariance instead of the estimated one, described below. &lt;code>gmmcovariance(tikhonov)&lt;/code> is the only covariance regularization available, with &lt;code>condition(1e-10)&lt;/code> and &lt;code>ridge(1e-4)&lt;/code> as fixed defaults. These are numerical settings, not identification thresholds or universally optimal tuning choices.&lt;/p>
&lt;h3 id="within-unit-weighting">Within-unit weighting&lt;/h3>
&lt;p>Holding the nuisance fits fixed, each comparison is a weighted sum of unit outcome changes between its two dates, $\hat{d}&lt;em>m = \sum_i \omega&lt;/em>{mi}(Y_{i t_m} - Y_{i s_m})$, where the loadings $\omega_{mi}$ are positive weights on the target cohort&amp;rsquo;s units and the IPW, OR or DR loadings on the control units. Suppose outcomes are a unit effect plus level shocks that are uncorrelated across units and dates, with variance proportional to $1/w_i$ for a unit with sampling weight $w_i$. &lt;code>gmmweighting(within)&lt;/code> uses the working weighting matrix built from&lt;/p>
&lt;p>$$
V_{ml} = 1{g_m = g_l}, \sigma_{ml} \sum_i \frac{\omega_{mi},\omega_{li}}{w_i}, \qquad
\sigma_{ml} = 1{t_m = t_l} + 1{s_m = s_l} - 1{t_m = s_l} - 1{s_m = t_l},
$$&lt;/p>
&lt;p>where $g_m$ is the target cohort of comparison $m$ and $(s_m, t_m)$ its dates. For two comparisons of the same target cohort, $V_{ml}$ is proportional to their covariance under these assumptions. Comparisons of different target cohorts that share control units are also correlated, but $V$ sets these entries to zero: it is a working matrix, block diagonal by target cohort. &lt;code>gmmweighting(within)&lt;/code> uses $V$ in place of the estimated covariance, after the exact reductions described next; the choice of weighting affects efficiency, not consistency. Comparisons of the same target cohort, control group and set of observed units that form cycles over dates are reduced to a spanning forest of each group, with $G = E&amp;rsquo;E$ for the removed comparisons. The weighting matrix does not depend on the outcome data, and standard errors still use the estimated unit influence functions, so inference does not rely on the level-shock model. It is available with or without &lt;code>selection(conditional_mtar)&lt;/code>, with every &lt;code>selmethod()&lt;/code>, with &lt;code>crosspair&lt;/code> and with covariates or weights that vary over time; with &lt;code>selection()&lt;/code>, &lt;code>outcomepooling(pooled)&lt;/code> or covariates that vary over time, it requires a constant in the covariate design. It is not available with &lt;code>method(custom)&lt;/code> or &lt;code>dvar()&lt;/code>.&lt;/p>
&lt;h2 id="exact-reductions-and-the-metric-of-the-full-set-of-comparisons">Exact reductions and the metric of the full set of comparisons&lt;/h2>
&lt;p>Before examining the sample covariance of the comparisons, &lt;code>cdid&lt;/code> removes comparisons that are exact linear combinations of others, when exact identities allow the full set to be reconstructed from the remaining comparisons (for example, with built-in IPW and no correction for missing outcomes, when distinct comparisons share the same cohort, control group and observed units).&lt;/p>
&lt;p>Suppose the full set contains $M$ comparisons and exact identities express the $M \times 1$ residual vector in terms of $L \le M$ remaining comparisons through a sparse $M \times L$ reconstruction matrix $E$:&lt;/p>
&lt;p>$$
\hat{d} - A\theta = E(\hat{d}_r - A_r\theta), \qquad G = E&amp;rsquo;E = C&amp;rsquo;C,
$$&lt;/p>
&lt;p>where $G$ is the symmetric positive-definite $L \times L$ Gram matrix of the reduction and $C$ is its upper-triangular Cholesky factor. When no reduction applies, $L = M$ and $G = C = I_M$.&lt;/p>
&lt;p>Preserving $G = E&amp;rsquo;E$ is essential for three reasons:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Exact preservation of the original $M$-comparison objective.&lt;/strong> Any weighting matrix $W$ of the full set becomes $E&amp;rsquo;WE$ on the $L$ remaining comparisons. In particular, under &lt;code>gmmweighting(identity)&lt;/code>, the unweighted objective over the full set is
$$
(\hat{d} - A\theta)' I_M (\hat{d} - A\theta) = (\hat{d}_r - A_r\theta)' E&amp;rsquo;E (\hat{d}_r - A_r\theta) = |C(\hat{d}_r - A_r\theta)|_2^2.
$$
The reduced system is therefore whitened by $C$, so that &lt;code>gmmweighting(identity)&lt;/code> still minimizes the exact sum of squares over all $M$ original comparisons, rather than replacing $G$ by a naive $I_L$ in reduced coordinates.&lt;/li>
&lt;li>&lt;strong>No arbitrary row dropping or spanning-tree subsetting.&lt;/strong> Correlation alone does not justify removing comparison rows; an exact reduction requires an exact identity, which can involve linear combinations rather than identical rows. Discarding correlated rows, deduplicating rows without preserving $G = E&amp;rsquo;E$, or restricting the set to a minimal set of comparisons that identifies the effects would change the estimator, and &lt;code>cdid&lt;/code> does none of these.&lt;/li>
&lt;li>&lt;strong>Algebraic identity is not extra sample information.&lt;/strong> When two comparisons evaluate the exact same sample difference on the same units, or when consecutive changes of the same balanced units telescope to a long change, the extra row repeats existing sample variation rather than adding independent information. Exact reduction removes this duplication without changing the criterion.&lt;/li>
&lt;/ol>
&lt;h2 id="covariance-conditioning-and-tikhonov-regularization">Covariance conditioning and Tikhonov regularization&lt;/h2>
&lt;p>Under &lt;code>gmmweighting(optimal)&lt;/code> (or &lt;code>two_step&lt;/code>), let $\widehat{V}_r$ denote the $L \times L$ covariance of the comparisons on the scale used for weighting, formed from the unit-level influence functions of the comparisons. This normalization need not equal the estimated covariance of $\hat d_r$ itself. A common positive rescaling of $\widehat V_r$ rescales its trace-proportional ridge equally and multiplies the criterion by a constant, leaving its minimizer unchanged. To respect the original $M$-comparison geometry when $L &amp;lt; M$, conditioning and regularization are defined in the $C$-transformed coordinates where the identity metric of the full set, $G = C&amp;rsquo;C$, becomes $I_L$. Define the transformed $L \times L$ symmetric covariance matrix&lt;/p>
&lt;p>$$
B = C \widehat{V}_r C'.
$$&lt;/p>
&lt;p>Adding an isotropic ridge $\lambda I_M$ in the original $M$-comparison coordinates corresponds in the reduced transformed coordinates to replacing $B$ by $B + \lambda I_L = C(\widehat{V}_r + \lambda G^{-1})C'$. The effective reduced weighting matrix is therefore&lt;/p>
&lt;p>$$
W_r(\lambda) = C'(B + \lambda I_L)^{-1} C = \left(\widehat{V}_r + \lambda G^{-1}\right)^{-1},
$$&lt;/p>
&lt;p>which reduces to $(\widehat{V}_r + \lambda I_M)^{-1}$ when $G = I_M$, and otherwise scales the ridge inversely with $G$ so that identical original comparisons receive the same metric weight regardless of how exact reduction grouped them.&lt;/p>
&lt;h3 id="how-the-weighting-is-chosen">How the weighting is chosen&lt;/h3>
&lt;p>After checking that $\widehat{V}&lt;em>r$ is finite and exactly symmetric and forming a symmetric finite $B$, the estimator computes a symmetric eigendecomposition of $B$ with minimum and maximum eigenvalues $d&lt;/em>{\min}(B)$ and $d_{\max}(B)$, checks that the eigendecomposition residual lies within floating-point roundoff bounds, and evaluates the reciprocal spectral condition ratio&lt;/p>
&lt;p>$$
\rho = \frac{\max(d_{\min}(B), 0)}{d_{\max}(B)}
$$&lt;/p>
&lt;p>(with $\rho = 0$ if $B = 0$). Materially negative eigenvalues or diagonal entries abort the fit; small negative eigenvalues consistent with floating-point roundoff are accepted only when $\widehat{V}_r$ was computed as a cross-product of unit influence functions, which makes it positive semidefinite in exact arithmetic.&lt;/p>
&lt;p>Estimation stops with an error if the eigendecomposition fails its numerical accuracy checks.&lt;/p>
&lt;p>The weighting then follows one of four cases; &lt;code>cdid_diagnostics&lt;/code> reports which one applied:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Case&lt;/th>
&lt;th>Condition&lt;/th>
&lt;th>Effective reduced weight and solution&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Well-conditioned unregularized solve&lt;/strong>&lt;/td>
&lt;td>$B$ is positive definite, $\rho \ge \tau_{\mathrm{cond}}$, the reduced dimension $L$ does not exceed the rank bound given by the number of contributing units, and ordinary Cholesky factorization of $\widehat V_r$ and the subsequent solve pass their checks&lt;/td>
&lt;td>$W_r(0) = C' B^{-1} C = \widehat{V}_r^{-1}$, implemented by Cholesky whitening of $\widehat V_r$ and pivoted QR factorization on the whitened design without regularization&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Tikhonov covariance ridge&lt;/strong>&lt;/td>
&lt;td>$B \ne 0$ and $\rho &amp;lt; \tau_{\mathrm{cond}}$, $d_{\min}(B) = 0$, $d_{\min}(B) &amp;lt; 0$ within roundoff, $L$ exceeds the sample rank upper bound, or unregularized Cholesky of $\widehat V_r$ fails after valid covariance diagnosis&lt;/td>
&lt;td>$W_r(\lambda) = C'(B + \lambda I_L)^{-1}C$ with $s = \mathrm{tr}(B)/M$ and $\lambda = \alpha_{\mathrm{ridge}} s$, solved by Cholesky factorization of $B + \lambda I_L$ and pivoted QR&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Exact-zero covariance limit&lt;/strong>&lt;/td>
&lt;td>$\widehat{V}_r = 0$ and $B = 0$ identically&lt;/td>
&lt;td>Scale-free least squares over all comparisons, with $\lambda = 0$ and reduced weight $G = C&amp;rsquo;C$ (whitened by $C$), paired with the actual zero sandwich covariance and zero-scale inference diagnostics&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Error: invalid covariance or failed solution&lt;/strong>&lt;/td>
&lt;td>$\widehat{V}_r$ or $B$ is nonfinite or materially indefinite, or the Cholesky or whitened-QR factorization fails its conditioning or residual bounds&lt;/td>
&lt;td>Estimation stops with an error; no estimate is returned&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Note three implementation details of this rule:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>The trace scale uses the number $M$ of comparisons in the full set.&lt;/strong> In the Tikhonov case, the scale is $s = \mathrm{tr}(B) / M$, where $M$ is the number of comparisons in the full set and $\mathrm{tr}(B) = \mathrm{tr}(\widehat{V}_r G)$ equals the trace of the full $M \times M$ moment covariance.&lt;/li>
&lt;li>&lt;strong>Stable factorizations rather than explicit matrix inversion.&lt;/strong> Neither the unregularized case nor the Tikhonov case forms an explicit dense inverse $B^{-1}$ or $(B + \lambda I_L)^{-1}$. The unregularized case whitens with the Cholesky factor of $\widehat V_r$; the ridge case uses that of $B+\lambda I_L$. Both then apply pivoted QR to the whitened design, and verify factor conditioning and relative residuals before accepting the solution.&lt;/li>
&lt;li>&lt;strong>No automatic repairs.&lt;/strong> The default values &lt;code>condition(1e-10)&lt;/code> and &lt;code>ridge(1e-4)&lt;/code> are numerical implementation settings, not universal optimal tuning parameters and not thresholds for parameter identification. If $B + \lambda I_L$ or the whitened QR factor still fails its conditioning checks, estimation stops with an error rather than increasing $\lambda$ iteratively, clipping eigenvalues, adding random jitter, dropping comparisons, or switching automatically to &lt;code>gmmweighting(identity)&lt;/code>.&lt;/li>
&lt;/ul>
&lt;h2 id="covariance-singularity-versus-parameter-identification">Covariance singularity versus parameter identification&lt;/h2>
&lt;p>Singular or near-singular moment covariance $\Sigma = \mathrm{Cov}(\hat{d})$ and non-identification of a target parameter $\tau = c'\theta$ are distinct mathematical phenomena. Moment covariance is a property of the stochastic errors across comparison rows. Parameter identification is a property of the design matrix $A$ and the maintained population restrictions $d = A\theta$.&lt;/p>
&lt;p>The two analytical examples below illustrate why neither implies the other. Here $\hat d$ denotes noisy comparisons and $d = E[\hat d]$ their population means. These are algebraic examples.&lt;/p>
&lt;h3 id="example-1-singular-moment-covariance-with-an-identified-parameter">Example 1: Singular moment covariance with an identified parameter&lt;/h3>
&lt;p>Suppose a scalar treatment effect $\theta$ is measured by two comparison moments that carry the exact same zero-mean shock $u$ with $\mathrm{Var}(u) = \sigma^2 &amp;gt; 0$:&lt;/p>
&lt;p>$$
\hat d_1 = \theta + u, \qquad \hat d_2 = \theta + u, \qquad A = \begin{pmatrix} 1 \ 1 \end{pmatrix}, \qquad \Sigma = \sigma^2 \begin{pmatrix} 1 &amp;amp; 1 \ 1 &amp;amp; 1 \end{pmatrix}.
$$&lt;/p>
&lt;p>Here the design matrix $A$ has column rank $1$, so $\theta = E[\hat d_1] = E[\hat d_2]$ is identified. Yet the $2 \times 2$ covariance matrix $\Sigma$ has rank $1$ and determinant $0$ because $\hat d_1 - \hat d_2 = 0$ with probability one. In chained estimation, a singular or near-singular covariance of this kind can arise when duplicate or telescoping comparison paths span the same dates. If the duplication is an exact structural equivalence, reduction collapses the pair to $L = 1$ with $G = E&amp;rsquo;E = 2$ and positive scalar variance. If this duplicated pair is kept without reduction, Tikhonov regularization replaces $\Sigma$ with $\Sigma + \lambda I_2$, which has eigenvalues $2\sigma^2 + \lambda$ and $\lambda &amp;gt; 0$, allowing the GMM step to form a well-defined convex combination of $\hat d_1$ and $\hat d_2$. Because both moments share the same shock $u$, the second moment adds no independent information, and the estimator variance remains $\sigma^2$.&lt;/p>
&lt;h3 id="example-2-nonsingular-moment-covariance-with-an-unidentified-parameter">Example 2: Nonsingular moment covariance with an unidentified parameter&lt;/h3>
&lt;p>Suppose instead that two parameters $\theta = (\theta_1, \theta_2)'$ (for instance, an unrestricted pre-period trend differential $\theta_1$ and a post-treatment effect $\theta_2$) enter a single available comparison moment with $\mathrm{Var}(u) = \sigma^2 &amp;gt; 0$:&lt;/p>
&lt;p>$$
\hat d_1 = \theta_1 + \theta_2 + u, \qquad A = \begin{pmatrix} 1 &amp;amp; 1 \end{pmatrix}, \qquad \Sigma = \begin{pmatrix} \sigma^2 \end{pmatrix}.
$$&lt;/p>
&lt;p>Here the $1 \times 1$ moment covariance $\Sigma = (\sigma^2)$ is strictly positive definite and well conditioned, but $A$ has rank $1 &amp;lt; 2$. The moment identifies the sum $\theta_1 + \theta_2$, while the individual contrast $\tau = \theta_2 = (0, 1)\theta$ is not in the row space of $A$. Adding a covariance ridge $\lambda &amp;gt; 0$ changes the scalar weight from $1/\sigma^2$ to $1/(\sigma^2 + \lambda)$, so the normal matrix&lt;/p>
&lt;p>$$
A'(\Sigma + \lambda)^{-1}A = \frac{1}{\sigma^2 + \lambda} \begin{pmatrix} 1 &amp;amp; 1 \ 1 &amp;amp; 1 \end{pmatrix}
$$&lt;/p>
&lt;p>still has rank $1$ and cannot be inverted for $\theta_1$ and $\theta_2$ separately. Because covariance regularization acts on $\Sigma$ rather than adding rows to $A$ or penalizing $\theta$, it never turns an unidentified parameter into an estimable one.&lt;/p>
&lt;h3 id="support-errors-and-precision">Support, errors, and precision&lt;/h3>
&lt;p>In &lt;code>cdid&lt;/code>, the availability of post-treatment effects is determined from the design $A$, before and independently of covariance regularization. Pretreatment cells, which are direct comparisons, have their own support rules:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Unsupported cells.&lt;/strong> When a target contrast $c_j'\theta$ does not lie in the row space of $A$ given the comparisons available and the chosen &lt;code>ptassumption()&lt;/code>, the cell is unavailable: its estimate and standard error are missing, and the results record the reason. This is a statement about the comparisons available in the sample, not a claim that the effect is unidentifiable in the population under every possible assumption.&lt;/li>
&lt;li>&lt;strong>Errors in the models or computations.&lt;/strong> Perfect separation, or a rank or support failure that remains in a required model after its permitted preprocessing, or a covariance or QR factorization that fails the applicable checks, stops the call with an error rather than returning an unavailable result for affected cells or dropping comparisons.&lt;/li>
&lt;li>&lt;strong>No uniform precision dominance.&lt;/strong> With independent units, valid moments, consistent covariance estimation, standard regularity and a nonsingular limiting covariance after exact reductions, the unregularized optimal weighting has the usual asymptotic efficiency property within the set of comparisons used. That statement does not automatically extend to the ridge case or to dependent units. Covariance ridge changes the weighting to obtain numerical conditioning when $B$ is singular or ill-conditioned, and &lt;code>gmmweighting(identity)&lt;/code> uses fixed weights over all comparisons. In finite samples, estimation noise in $\widehat{V}_r$ can offset theoretical efficiency gains, so neither &lt;code>gmmweighting(optimal)&lt;/code>, nor a particular &lt;code>ridge()&lt;/code>, nor &lt;code>gmmweighting(identity)&lt;/code> is guaranteed to produce smaller finite-sample variance or mean squared error in every setting.&lt;/li>
&lt;/ul>
&lt;h2 id="sandwich-inference-and-clustering">Sandwich inference and clustering&lt;/h2>
&lt;p>The weighting matrix determines the point-estimate loadings. It is not inverted to report parameter uncertainty. The influence functions have one row per unit of the study population, including units without an observed pair, and account for the estimation of the adjustment models and, in aggregations, of the cohort shares.&lt;/p>
&lt;p>&lt;code>e(V)&lt;/code> is analytical estimator covariance. &lt;code>e(V_asymptotic)&lt;/code> is &lt;code>e(N_full)&lt;/code> times that covariance; &lt;code>e(analytic_se)&lt;/code> is the square root of the diagonal of &lt;code>e(V)&lt;/code>. The reported &lt;code>e(se)&lt;/code> can instead come from the multiplier bootstrap. With &lt;code>noinffunc&lt;/code>, the GMM weighting is computed as usual, so the point estimates are unchanged, but no inference is returned and &lt;code>estat&lt;/code> cannot aggregate the results.&lt;/p>
&lt;p>Clustering sums unit influence functions for inference. It does not change unit-based GMM weights or point estimates, and optimal weighting is not claimed to be cluster-optimal. First-order inference requires valid moments, regular estimators of the comparisons, consistent covariance estimates and a stable limiting case of the weighting. No uniform boundary or few-cluster coverage guarantee follows from a successful fit.&lt;/p>
&lt;h2 id="examples-and-computational-limits">Examples and computational limits&lt;/h2>
&lt;p>With the data of the hands-on do-file in memory, compare the same effects under analytical inference:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) gmmweighting(optimal) bstrap(0) cband(0)
cdid_diagnostics, detail
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) gmmweighting(identity) bstrap(0) cband(0)
cdid_diagnostics, detail
&lt;/code>&lt;/pre>
&lt;p>&lt;code>workspace()&lt;/code> defaults to 1073741824 bytes (1 GiB). Without &lt;code>chunk()&lt;/code>, the number of rows processed at a time is set automatically. Without &lt;code>workcap()&lt;/code>, the number of operations is not limited; &lt;code>workcap()&lt;/code> counts operations conservatively, not seconds. These limits do not bound the total memory or time used by Stata and do not relax any statistical check.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 15 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/pt-all-comparison/">Add PT-all restrictions&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/">Compare model robustness across treatment and missing outcome adjustments&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Handling missing outcomes</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/</guid><description>&lt;p>In an incomplete panel, only a subset of units is observed at both endpoints of any ordered calendar pair $e = (s, t)$. If the units observed on pair $e$ differ systematically in their outcome &lt;strong>changes&lt;/strong> $\Delta_e Y = Y_t - Y_s$ from the rest of their cohort in the study population $F$, unadjusted cohort pair averages no longer represent the full study population.&lt;/p>
&lt;p>&lt;code>cdid&lt;/code> separates &lt;strong>the identifying assumption about missing outcomes&lt;/strong> (&lt;code>selection()&lt;/code>) from &lt;strong>the estimator and the models used to adjust for missing outcomes&lt;/strong> (&lt;code>selmethod()&lt;/code>, &lt;code>selmodel()&lt;/code>, &lt;code>selpooling()&lt;/code>, &lt;code>imppooling()&lt;/code>).&lt;/p>
&lt;h2 id="the-study-population">The study population&lt;/h2>
&lt;p>Every chained &lt;code>cdid&lt;/code> fit targets the average treatment effect over the &lt;strong>study population $F$&lt;/strong> (&lt;code>frame(name)&lt;/code>, or all units in the estimation sample when &lt;code>frame()&lt;/code> is omitted), except that under &lt;code>missingreference(exclude)&lt;/code> a cohort whose treated units lack a required covariate at the reference date is estimated for its eligible treated units (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/">Prepare your data&lt;/a>):&lt;/p>
&lt;ul>
&lt;li>&lt;strong>$F$ (&lt;code>e(N_full)&lt;/code>):&lt;/strong> All study units, including singletons observed at only one date ($B \setminus A$) and unit-table-only units observed at zero dates ($F \setminus B$).&lt;/li>
&lt;li>&lt;strong>$B$:&lt;/strong> Units observed at $\ge 1$ date.&lt;/li>
&lt;li>&lt;strong>$A$ :&lt;/strong> Units observed at $\ge 2$ dates.&lt;/li>
&lt;/ul>
&lt;p>Even though a unit in $F \setminus A$ (observed once or never) supplies no raw change $\Delta_e Y_i$, it remains a member of its cohort in $F$: its baseline covariates in &lt;code>frame()&lt;/code> enter observation-logit fitting on &lt;code>seluniverse(F)&lt;/code>, actual-change imputation predictions on $F$, cohort weights in &lt;code>estat&lt;/code>, cluster sums, and the complete $N_F$-row influence functions.&lt;/p>
&lt;h2 id="without-an-observation-model-selectionnone-default">Without an observation model (&lt;code>selection(none)&lt;/code>, default)&lt;/h2>
&lt;p>With &lt;code>selection(none)&lt;/code>, &lt;code>cdid&lt;/code> fits no observation-probability model $q$ and no change-imputation model $j$. For each cohort $k$ and date pair $e = (s, t)$, observed changes on $S_e = 1$ are scaled by the cohort&amp;rsquo;s empirical pair response rate on $F$ and passed directly to treatment adjustment (&lt;code>method(dr|reg|ipw)&lt;/code>).&lt;/p>
&lt;p>This requires &lt;strong>unconditional mean-change representativeness within each cohort&lt;/strong>:&lt;/p>
&lt;p>$$E[Y_t - Y_s \mid G = k, S_{s,t} = 1] = E[Y_t - Y_s \mid G = k]$$&lt;/p>
&lt;p>As shown in &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/identification/">Identify effects when the observed units change composition&lt;/a>, this condition concerns outcome &lt;strong>changes&lt;/strong> $Y_t - Y_s$, not outcome levels $Y_t$ or unit fixed effects $\alpha_i$. However, if a covariate $W_i$ shifts both the probability of observing pair $e$ ($S_{s,t} = 1$) and the outcome change $Y_t - Y_s$ within cohort $k$, &lt;code>selection(none)&lt;/code> is generally biased for the population $F$.&lt;/p>
&lt;h2 id="conditional-mean-trends-missing-at-random-selectionconditional_mtar">Conditional mean trends missing at random (&lt;code>selection(conditional_mtar)&lt;/code>)&lt;/h2>
&lt;p>Setting &lt;code>selection(conditional_mtar)&lt;/code> invokes the &lt;strong>Conditional Mean Trends Missing at Random&lt;/strong> assumption (Corollary 1 of Bellégo, Benatia and Dortet-Bernadet 2025): conditional on covariates $W_i$ and cohort $G_i = k$, the mean outcome change over pair $e = (s, t)$ is the same among units observed at both endpoints ($S_{s,t} = 1$) and in the full cohort $G_i = k$ on $F$:&lt;/p>
&lt;p>$$E[Y_t - Y_s \mid W, G = k, S_{s,t} = 1] = E[Y_t - Y_s \mid W, G = k]$$&lt;/p>
&lt;p>This condition must hold for &lt;strong>every&lt;/strong> cohort $k$ (both treated and control cohorts, including actual post-treatment changes of treated cohorts) and &lt;strong>every&lt;/strong> date pair $e = (s, t)$ used in the comparisons.&lt;/p>
&lt;blockquote>
&lt;p>[!NOTE]
&lt;strong>Distinguishing the assumption from the estimator:&lt;/strong> &lt;code>selection(conditional_mtar)&lt;/code> states the conditional mean-independence assumption above. How &lt;code>cdid&lt;/code> estimates the cohort population changes under that assumption is chosen separately by &lt;code>selmethod(ipw|imputation|dr)&lt;/code>.&lt;/p>
&lt;/blockquote>
&lt;h2 id="three-estimators-under-selectionconditional_mtar">Three estimators under &lt;code>selection(conditional_mtar)&lt;/code>&lt;/h2>
&lt;h3 id="1-observation-weighting-selmethodipw-default">1. Observation weighting (&lt;code>selmethod(ipw)&lt;/code>, default)&lt;/h3>
&lt;p>&lt;code>selmethod(ipw)&lt;/code> estimates the probability $q_c(W_i) = P(S_e = 1 \mid G_i = k, W_i)$ of observing both endpoints of pair $e = (s, t)$ for each needed cell $c = (k, e)$, and reweights observed changes ($S_{i,e} = 1$) by $1 / \max(\hat{q}_c(W_i), 10^{-6})$ (combined with the cohort&amp;rsquo;s empirical pair rate and any transport factor &lt;code>selrho()&lt;/code>).&lt;/p>
&lt;p>You choose the parametric observation model $q_c(W)$ with two options:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>&lt;code>selmodel(pair_logit|independent_period_logit)&lt;/code>:&lt;/strong>
&lt;ul>
&lt;li>&lt;code>pair_logit&lt;/code> (default): directly fits a binary logit for the pair indicator $S_{i,e} = R_{i,s} R_{i,t} \in {0, 1}$.&lt;/li>
&lt;li>&lt;code>independent_period_logit&lt;/code>: fits binary logits for single-date observation $R_{i,s}$ and $R_{i,t}$ and multiplies the two fitted date probabilities: $\hat{q}&lt;em>{k,(s,t)}(W_i) = \hat{r}&lt;/em>{k,s}(W_i),\hat{r}_{k,t}(W_i)$. This requires conditional independence of the two endpoint observation indicators given cohort and the scientifically sufficient covariates. It requires &lt;code>seluniverse(F)&lt;/code>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>&lt;code>selpooling(separate|within_cohort|across_cohorts)&lt;/code>:&lt;/strong>
All three pooling choices retain a &lt;strong>separate intercept for every cell&lt;/strong> (whenever an intercept is included) and impose different restrictions on the covariate slope vector of $q$:
&lt;ul>
&lt;li>&lt;code>separate&lt;/code> (default): separate slope vector for every cell $(k, e)$ (under &lt;code>pair_logit&lt;/code>) or every cohort-date $(k, d)$ (under &lt;code>independent_period_logit&lt;/code>).&lt;/li>
&lt;li>&lt;code>within_cohort&lt;/code>: one shared slope vector per cohort $k$ across its date pairs or dates.&lt;/li>
&lt;li>&lt;code>across_cohorts&lt;/code>: one global slope vector shared across all cohorts and pairs/dates.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>Under &lt;code>selmethod(ipw)&lt;/code>, &lt;code>imppooling()&lt;/code> does not apply (&lt;code>e(inactive_options)&lt;/code> lists it, together with &lt;code>outcomepooling()&lt;/code> under &lt;code>method(ipw|custom)&lt;/code>), and no imputation model $j$ is fitted.&lt;/p>
&lt;h3 id="2-change-imputation-selmethodimputation">2. Change imputation (&lt;code>selmethod(imputation)&lt;/code>)&lt;/h3>
&lt;p>Instead of fitting observation probabilities $q_c$, &lt;code>selmethod(imputation)&lt;/code> fits a weighted least squares linear model $j_c(X_i)$ for the &lt;strong>actual outcome change&lt;/strong> $\Delta_{i,e} = Y_{i,t} - Y_{i,s}$ on units of cohort $k$ observed at both dates ($S_{i,e} = 1$):&lt;/p>
&lt;p>$$j_{k,e}(X_i) = \alpha_{k,e} + L(e), z(X_i)'\beta_r$$&lt;/p>
&lt;p>where $L(e) = i_t - i_s$ is the step count in the stored calendar, $\alpha_{k,e}$ is a local cell intercept (unless &lt;code>noconstant&lt;/code> is specified), and $\beta_r$ is the slope vector of imputation pooling group $r$ controlled by &lt;strong>&lt;code>imppooling(separate|within_cohort|across_cohorts)&lt;/code>&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;code>imppooling(separate)&lt;/code> (default): separate slope vector $\beta_{k,e}$ for every cohort and date pair cell $(k, e)$.&lt;/li>
&lt;li>&lt;code>imppooling(within_cohort)&lt;/code>: one shared slope vector $\beta_k$ per cohort across all of its date pairs.&lt;/li>
&lt;li>&lt;code>imppooling(across_cohorts)&lt;/code>: one global slope vector $\beta$ shared across all cohorts and date pairs.&lt;/li>
&lt;/ul>
&lt;p>For each cell $(k, e)$, &lt;code>cdid&lt;/code> evaluates $\hat{j}_{k,e}(X_i)$ for &lt;strong>every unit of cohort $k$ in the full study population $F$&lt;/strong> (including units whose change was observed, singletons, and unobserved unit-table units) and averages those predictions over $F$ before applying treatment adjustment (&lt;code>method(dr|reg|ipw)&lt;/code>).&lt;/p>
&lt;ul>
&lt;li>Under &lt;code>selmethod(imputation)&lt;/code>, &lt;code>selmodel()&lt;/code>, &lt;code>selpooling()&lt;/code>, and &lt;code>selcovars()&lt;/code>/&lt;code>frameselcovars()&lt;/code> do &lt;strong>not&lt;/strong> apply (&lt;code>e(inactive_options)&lt;/code> lists them, together with &lt;code>outcomepooling()&lt;/code> under &lt;code>method(ipw)&lt;/code>), and no observation logit is fitted.&lt;/li>
&lt;li>Pure imputation requires &lt;code>seluniverse(F)&lt;/code> and does not allow transport weights (&lt;code>selrho()&lt;/code>).&lt;/li>
&lt;/ul>
&lt;h3 id="3-augmented-doubly-robust-correction-selmethoddr">3. Augmented doubly robust correction (&lt;code>selmethod(dr)&lt;/code>)&lt;/h3>
&lt;p>&lt;code>selmethod(dr)&lt;/code> combines the actual-change imputer $j_c(X_i)$ and the observation-probability model $q_c(W_i)$ on &lt;code>seluniverse(F)&lt;/code> (without &lt;code>selrho()&lt;/code>) and works with all three built-in treatment methods: &lt;code>method(ipw)&lt;/code>, &lt;code>method(reg)&lt;/code>, and &lt;code>method(dr)&lt;/code> (&lt;code>method(custom)&lt;/code> is not supported).&lt;/p>
&lt;p>For each needed cell $c = (k, e)$, every unit $i$ of cohort $k$ in $F$ receives the reconstructed change:&lt;/p>
&lt;p>$$Z_{i,c} = \hat{j}&lt;em>c(X_i) + S&lt;/em>{i,e},\frac{\Delta_{i,e} - \hat{j}_c(X_i)}{\max(\hat{q}_c(W_i),, 10^{-6})}$$&lt;/p>
&lt;p>The residual term is not renormalized. Built-in treatment adjustment then runs on the reconstructed changes $Z_{i,c}$:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>&lt;code>method(ipw)&lt;/code>:&lt;/strong> fits $q_c, j_c$ and risk-set treatment logits $p$ (no $m$; &lt;code>outcomepooling()&lt;/code> does not apply). Consistent if ($q_c$ or $j_c$) and $p$ are correctly specified.&lt;/li>
&lt;li>&lt;strong>&lt;code>method(reg)&lt;/code>:&lt;/strong> fits $q_c, j_c$ and counterfactual control regressions $m_b$ (with &lt;code>outcomepooling(separate|pooled)&lt;/code>, no $p$). Consistent if ($q_c$ or $j_c$) and $m$ are correctly specified.&lt;/li>
&lt;li>&lt;strong>&lt;code>method(dr)&lt;/code>:&lt;/strong> fits $q_c, j_c, p$, and $m_b$ (doubly robust in both layers). Consistent if ($q_c$ or $j_c$) is correctly specified on the common conditioning set $W$ and ($p$ or $m$) is correctly specified (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/">Compare model robustness&lt;/a>).&lt;/li>
&lt;/ul>
&lt;h2 id="separate-covariate-lists-covars-vs-selcovars">Separate covariate lists (&lt;code>covars()&lt;/code> vs &lt;code>selcovars()&lt;/code>)&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> lets you specify separate covariate lists for the treatment/imputation design $X$ and the observation-probability design $Q$:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Models using this design&lt;/th>
&lt;th>Default / intercept controls&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>indepvars&lt;/code> or &lt;code>covars(varlist)&lt;/code>, &lt;code>framecovars(varlist)&lt;/code>&lt;/td>
&lt;td>Treatment logit $p$, counterfactual control regression $m$, actual-change imputer $j$&lt;/td>
&lt;td>Includes an intercept unless &lt;code>noconstant&lt;/code> is specified.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selcovars(varlist)&lt;/code>, &lt;code>frameselcovars(varlist)&lt;/code>&lt;/td>
&lt;td>Observation-probability logit $q$ (&lt;code>selmethod(ipw)&lt;/code> or &lt;code>selmethod(dr)&lt;/code>)&lt;/td>
&lt;td>Inherits &lt;code>covars()&lt;/code> / &lt;code>framecovars()&lt;/code> when omitted. Intercept controls: &lt;code>selnoconstant&lt;/code> (omit intercept), &lt;code>selconstant&lt;/code> (intercept-only &lt;code>~ 1&lt;/code>), &lt;code>selzero&lt;/code> (empty design &lt;code>~ 0&lt;/code>, fixing pair probability to $0.5$ under &lt;code>pair_logit&lt;/code> or $0.25$ under &lt;code>independent_period_logit&lt;/code>).&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="probability-safeguards">Probability safeguards&lt;/h2>
&lt;p>Two fixed numerical safeguards, the same as in R &lt;code>cdid&lt;/code>, prevent division by zero in inverse probability weights without dropping observations:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Treatment propensity cap (&lt;code>1 - 1e-6&lt;/code>):&lt;/strong> Fitted risk-set propensities $\hat{p}_{g,K,e}(X_i)$ are capped above at $0.999999$ .&lt;/li>
&lt;li>&lt;strong>Observation probability floor (&lt;code>1e-6&lt;/code>):&lt;/strong> Fitted pair observation probabilities $\hat{q}_c(W_i)$ entering inverse observation weights (&lt;code>selmethod(ipw)&lt;/code> and &lt;code>selmethod(dr)&lt;/code>) are floored below at $10^{-6}$. With independent-period logits, the floor applies to the product for the pair, not to each date. Positive empirical observation rates used as denominators have the same floor. Scores and information matrices use the unbounded probabilities, and the derivatives of the weights account for the bounds where they bind. The number of bounded probabilities is displayed when it was stored.&lt;/li>
&lt;/ol>
&lt;p>The robustness statements about the original target require that the bounds do not bind in the population (or other conditions that preserve the target), and that crossings of the bounds be negligible for the usual influence-function argument. Binding bounds can change the target and the robustness properties. The bounds provide no identification and no guarantee of nominal coverage.&lt;/p>
&lt;h2 id="with-presetcohort_time_fe">With &lt;code>preset(cohort_time_fe)&lt;/code>&lt;/h2>
&lt;p>The cohort-by-date preset applies the same three estimators to every pair of dates $e = (s, t)$ observed for at least one unit of cohort $k$. Each unit $i$ of the cohort in $F$, including units observed at fewer than two dates, receives a corrected change&lt;/p>
&lt;p>$$Z_i(k; s, t) = \begin{cases} S_{i,e}, \Delta_e Y_i / \hat q_{k,e}(W_i) &amp;amp; \text{selmethod(ipw)} \ \hat j_{k,e}(X_i) &amp;amp; \text{selmethod(imputation)} \ \hat j_{k,e}(X_i) + S_{i,e},{\Delta_e Y_i - \hat j_{k,e}(X_i)} / \hat q_{k,e}(W_i) &amp;amp; \text{selmethod(dr)} \end{cases}$$&lt;/p>
&lt;p>where $\hat q_{k,e}$ is the pair logit (or the product of the two date logits) and $\hat j_{k,e}(X) = a_{k,e} + (t - s), X&amp;rsquo;b$ is the imputation regression, pooled as set by &lt;code>selpooling()&lt;/code> and &lt;code>imppooling()&lt;/code>. With &lt;code>method(reg)&lt;/code>, the cohort-by-date and date levels are fitted by least squares of $Z_i(k; s, t)$ on the difference of the levels of $t$ and $s$, with the covariates entering as in the regression without missing outcomes; with &lt;code>method(ipw)&lt;/code> or &lt;code>method(dr)&lt;/code>, the corrected changes replace the observed changes in the treatment moments, each averaged over all units of its cohort. With &lt;code>seluniverse(B)&lt;/code> or &lt;code>seluniverse(A)&lt;/code> (only with &lt;code>selmodel(pair_logit)&lt;/code> and &lt;code>selmethod(ipw)&lt;/code>), the denominator is $\hat\pi_k, \rho_i \max{\hat q_{k,e}(W_i), 10^{-6}}$, where $\hat\pi_k$ is the share of cohort $k$ in the fitting roster. The standard errors include the estimation of $\hat q$, $\hat\pi$ and $\hat j$. &lt;code>keepnuisance&lt;/code> keeps all fitted models for &lt;code>cdid_nuisance&lt;/code>.&lt;/p>
&lt;h2 id="summary-of-the-9-supported-built-in-combinations-under-selectionconditional_mtar">Summary of the 9 supported built-in combinations under &lt;code>selection(conditional_mtar)&lt;/code>&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;code>selmethod()&lt;/code>&lt;/th>
&lt;th>&lt;code>method(ipw)&lt;/code>&lt;/th>
&lt;th>&lt;code>method(reg)&lt;/code>&lt;/th>
&lt;th>&lt;code>method(dr)&lt;/code>&lt;/th>
&lt;th>Models fitted&lt;/th>
&lt;th>Allowed &lt;code>seluniverse()&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>selmethod(ipw)&lt;/code>&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>$q$ + ($p$, $m$, or $p,m$)&lt;/td>
&lt;td>&lt;code>F&lt;/code> (default); &lt;code>B&lt;/code> or &lt;code>A&lt;/code> only for &lt;code>pair_logit&lt;/code>, with &lt;code>seljustification()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(imputation)&lt;/code>&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>$j$ + ($p$, $m$, or $p,m$)&lt;/td>
&lt;td>&lt;code>F&lt;/code> only (&lt;code>selrho()&lt;/code> not allowed)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(dr)&lt;/code>&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>Supported&lt;/td>
&lt;td>$q, j$ + ($p$, $m$, or $p,m$)&lt;/td>
&lt;td>&lt;code>F&lt;/code> only (&lt;code>selrho()&lt;/code> not allowed)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Other assumptions about missing outcomes, such as sequential missingness with permanent dropout, are not implemented in &lt;code>cdid&lt;/code>.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 9 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/treatment-choice/">Choose IPW, OR or DR in an incomplete panel&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/sampling-information/">Sampling information for the observation model&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Hands-on guide to cdid in Stata</title><link>https://www.davidbenatia.com/tools/cdid/stata/hands-on/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/hands-on/</guid><description>&lt;p>This guide walks through a complete analysis with &lt;code>cdid&lt;/code>, using the do-file &lt;code>examples/cdid_hands_on.do&lt;/code>. Run the do-file from top to bottom, or run Section 0 and Section 1, which creates the data, and then run later sections from the Do-file Editor. Later sections use the simulated data already in memory.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Stata package repository&lt;/strong>: &lt;a href="https://github.com/dvbn/cdid-stata" target="_blank" rel="noopener">https://github.com/dvbn/cdid-stata&lt;/a>&lt;/li>
&lt;li>&lt;strong>R package&lt;/strong>: &lt;a href="https://github.com/dvbn/cdid" target="_blank" rel="noopener">https://github.com/dvbn/cdid&lt;/a>&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="0-settings">0. Settings&lt;/h2>
&lt;p>Before running &lt;code>examples/cdid_hands_on.do&lt;/code>, start a new Stata session or save the data in memory. The settings are global macros; values you set before running the do-file are kept. Section 0 gives each unset &lt;code>CDID_DEMO_*&lt;/code> global its default value and defines a small program, &lt;code>cdid_demo_init&lt;/code>, so that individual sections can be run from the Do-file Editor with your settings:&lt;/p>
&lt;pre>&lt;code class="language-stata">global CDID_DEMO_CLEAR_OK 0 // Set to 1 to allow Section 1 to clear memory
global CDID_DEMO_N 800 // Number of units (600-1000 recommended)
global CDID_DEMO_T 6 // Number of calendar periods (5 or 6 recommended)
global CDID_DEMO_SEED 20261103 // Random-number seed for the simulated data
global CDID_DEMO_BITERS 199 // Bootstrap draws (package default is 1000)
global CDID_DEMO_MISS_LAW &amp;quot;conditional_mtar&amp;quot; // &amp;quot;mcar&amp;quot;, &amp;quot;conditional_mtar&amp;quot;, or &amp;quot;rotating_window&amp;quot;
global CDID_DEMO_MISS_STRENGTH 0.85 // Strength of covariate-driven observation log-odds
global CDID_DEMO_TREND_HET 0.35 // Covariate slope in untreated outcome changes
global CDID_DEMO_EFF_BASE 1.20 // Baseline post-treatment causal effect
global CDID_DEMO_EFF_SLOPE 0.30 // Effect growth per event-time period after treatment
global CDID_DEMO_EFF_HET 0.25 // Effect heterogeneity by binary covariate x_bin
global CDID_DEMO_RUN_ADVANCED 0 // Set to 1 to run optional advanced comparisons
global CDID_DEMO_OUTDIR &amp;quot;&amp;quot; // Folder for graphs, datasets and saved results (&amp;quot;&amp;quot; = temporary files only)
global CDID_DEMO_REPLACE 0 // Set to 1 to allow cdid_plot/cdid_export to overwrite files
&lt;/code>&lt;/pre>
&lt;h3 id="conventions">Conventions&lt;/h3>
&lt;ol>
&lt;li>&lt;strong>Bootstrap draw count&lt;/strong>: The package default in both &lt;code>cdid&lt;/code> and &lt;code>cdid_pretest&lt;/code> is &lt;code>biters(1000)&lt;/code>. The do-file sets &lt;code>CDID_DEMO_BITERS = 199&lt;/code> so that the examples run quickly.&lt;/li>
&lt;li>&lt;strong>Memory and files&lt;/strong>: Section 1 clears the data in memory only if &lt;code>CDID_DEMO_CLEAR_OK&lt;/code> is 1. Set &lt;code>CDID_DEMO_OUTDIR&lt;/code> to keep graphs, exported datasets and saved results in a folder. Without it, the do-file exports datasets and saves results to temporary files and skips graph saving. Existing graphs and datasets are replaced only if &lt;code>CDID_DEMO_REPLACE&lt;/code> is 1.&lt;/li>
&lt;/ol>
&lt;hr>
&lt;h2 id="1-data-requirements-and-the-simulated-panel">1. Data requirements and the simulated panel&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> expects a long panel dataset where each row represents a unique &lt;code>(ivar, time)&lt;/code> pair:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Unit identifier (&lt;code>ivar(varname)&lt;/code>)&lt;/strong>: Numeric or string identifier uniquely identifying each unit in each period.&lt;/li>
&lt;li>&lt;strong>Calendar time (&lt;code>time(varname)&lt;/code>)&lt;/strong>: Numeric calendar date (for example, &lt;code>1, 2, ..., 6&lt;/code> or &lt;code>2018, 2019, ..., 2023&lt;/code>).&lt;/li>
&lt;li>&lt;strong>Treatment cohort (&lt;code>gvar(varname)&lt;/code>)&lt;/strong>: Time-constant numeric first-treatment date for each unit. Never-treated control units must be coded as &lt;code>0&lt;/code>; treated units carry the numeric calendar period in which treatment begins (for example, &lt;code>3&lt;/code> or &lt;code>5&lt;/code>).&lt;/li>
&lt;li>&lt;strong>Missing outcomes in long data&lt;/strong>: Every unit can be represented in the long dataset across all dates even when the outcome &lt;code>y&lt;/code> is missing (&lt;code>y == .&lt;/code>). Rows with missing &lt;code>y&lt;/code> keep their unit identifier, calendar date, cohort &lt;code>gvar()&lt;/code>, covariates, cluster identifier, and sampling weights so &lt;code>cdid&lt;/code> can use full unit-level covariate and observation-history information.&lt;/li>
&lt;li>&lt;strong>Separate unit-level population table (&lt;code>frame()&lt;/code>)&lt;/strong>: When some units in the target population have zero observed outcomes (or do not appear in the outcome panel at all), you can supply a one-row-per-unit Stata frame via &lt;code>frame(name)&lt;/code> along with &lt;code>frameivar()&lt;/code>, &lt;code>framegvar()&lt;/code>, &lt;code>framecovars()&lt;/code>, &lt;code>frameselcovars()&lt;/code>, &lt;code>framewvar()&lt;/code>, and &lt;code>framecluster()&lt;/code>.&lt;/li>
&lt;/ul>
&lt;h3 id="the-simulated-data">The simulated data&lt;/h3>
&lt;p>In Section 1 of &lt;code>examples/cdid_hands_on.do&lt;/code>, we generate $N = 800$ units over $T = 6$ periods with staggered cohorts &lt;code>first_treat&lt;/code> $\in {0, 3, 5}$, unit fixed effects $\alpha_i$, binary covariate &lt;code>x_bin&lt;/code>, continuous covariate &lt;code>x_cont&lt;/code>, and selection predictor &lt;code>z_sel&lt;/code>. Untreated potential outcomes are generated from their &lt;strong>changes&lt;/strong>:&lt;/p>
&lt;p>$$\Delta Y_{it}(0) = Y_{it}(0) - Y_{i,t-1}(0) = \delta_t + \theta_1 \text{x_bin}&lt;em>i + \theta_2 \text{x_cont}&lt;em>i + (\varepsilon&lt;/em>{it} - \varepsilon&lt;/em>{i,t-1})$$&lt;/p>
&lt;p>Because chained DiD operates on within-unit outcome differences $Y_{it} - Y_{is}$, the unit fixed effects $\alpha_i$ in outcome levels cancel. Identification does not require observed and unobserved units to have equal outcome levels.&lt;/p>
&lt;hr>
&lt;h2 id="2-units-observed-at-both-dates-the-study-population-and-missingness-checks">2. Units observed at both dates, the study population, and missingness checks&lt;/h2>
&lt;h3 id="units-observed-at-both-dates-and-the-study-population">Units observed at both dates and the study population&lt;/h3>
&lt;p>To estimate the group-time average treatment effect $ATT(g,t)$ through a chain of transitions $(s, t)$, &lt;code>cdid&lt;/code> forms elementary within-unit differences $\Delta Y_{i,s,t} = Y_{it} - Y_{is}$ among the units in cohort $g$ (or the control group) whose outcomes are observed at &lt;strong>both&lt;/strong> dates $s$ and $t$ ($R_{is} R_{it} = 1$).&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Mean-change representativeness&lt;/strong>: Under the stated conditioning (unconditional in baseline &lt;code>selection(none)&lt;/code>, or conditional on the specified covariates in &lt;code>selection(conditional_mtar)&lt;/code>), &lt;strong>units observed at both endpoints represent the cohort with respect to the mean outcome change&lt;/strong> between $s$ and $t$.&lt;/li>
&lt;li>&lt;strong>Study population&lt;/strong>: although each comparison $(s,t)$ is estimated from the units observed at both $s$ and $t$, cohort shares and aggregation weights are computed over the study population of $N$ units (all units of the unit table), not over the units observed at both dates.&lt;/li>
&lt;/ul>
&lt;h3 id="practical-missingness-checks-before-estimation">Practical Missingness Checks Before Estimation&lt;/h3>
&lt;p>Before fitting &lt;code>cdid&lt;/code>, always inspect observation patterns in the long panel (Section 2):&lt;/p>
&lt;pre>&lt;code class="language-stata">* 2a. Count observed outcome dates per unit across all units in the long dataset
tempvar n_obs_unit tag_unit
bysort id: egen long `n_obs_unit' = count(y)
bysort id: generate byte `tag_unit' = (_n == 1)
tabulate `n_obs_unit' first_treat if `tag_unit', missing
* 2b. Inspect outcome observation rates by calendar period and cohort
tabulate period first_treat, summarize(obs_y) means
* 2c. Compare covariate composition across all units vs repeat-observer units (&amp;gt;=2 dates)
summarize x_bin x_cont z_sel if `tag_unit'
summarize x_bin x_cont z_sel if `tag_unit' &amp;amp; `n_obs_unit' &amp;gt;= 2
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="3-chained-estimation-control-groups-base-periods-parallel-trends-and-treatment-adjustment">3. Chained estimation: control groups, base periods, parallel trends and treatment adjustment&lt;/h2>
&lt;p>Section 3 demonstrates the core model specification options of &lt;code>cdid&lt;/code>:&lt;/p>
&lt;pre>&lt;code class="language-stata">* 3a. Doubly robust (DR) chained estimation with never-treated controls and varying base period
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) controlgroup(nevertreated) baseperiod(varying) ///
biters($CDID_DEMO_BITERS)
* Redisplay the results without refitting
cdid
* 3b. Not-yet-treated control group and universal base period
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) controlgroup(notyettreated) baseperiod(universal) ///
biters($CDID_DEMO_BITERS)
* 3c. Parallel trends over all periods from `ptstart(1)`
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) controlgroup(nevertreated) ptassumption(all) ptstart(1) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;h3 id="key-choices">Key Choices&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>&lt;code>controlgroup(nevertreated|notyettreated)&lt;/code>&lt;/strong>: &lt;code>nevertreated&lt;/code> uses units with &lt;code>first_treat == 0&lt;/code>. &lt;code>notyettreated&lt;/code> expands the comparison group for transition $(s,t)$ to include cohorts not yet treated by $\max(s,t) + \text{anticipation}$.&lt;/li>
&lt;li>&lt;strong>&lt;code>baseperiod(varying|universal)&lt;/code>&lt;/strong>: Controls the reporting baseline for pre-treatment cells (&lt;code>varying&lt;/code> uses adjacent pre-treatment transitions; &lt;code>universal&lt;/code> anchors to the reference date $r(g)$, the latest study date before $g - \text{anticipation}$, which is $g - 1 - \text{anticipation}$ when the dates are consecutive integers).&lt;/li>
&lt;li>&lt;strong>&lt;code>ptassumption(post|all)&lt;/code>&lt;/strong>: &lt;code>baseperiod()&lt;/code> and &lt;code>ptassumption()&lt;/code> are independent settings. &lt;code>ptassumption(post)&lt;/code> (default) enforces parallel trends only from $r(g)$ onward, leaving pre-treatment differences unrestricted for pretrend testing. &lt;code>ptassumption(all)&lt;/code> imposes parallel trends from the common calendar date given in &lt;code>ptstart(#)&lt;/code>, adding comparisons before the reference period to the GMM system.&lt;/li>
&lt;li>&lt;strong>&lt;code>method(dr|reg|ipw)&lt;/code> and &lt;code>outcomepooling(separate|pooled)&lt;/code>&lt;/strong>: Selects how treatment nuisance models adjust for covariates $X$:
&lt;ul>
&lt;li>&lt;code>method(ipw)&lt;/code> reweights control outcome changes using propensity scores (&lt;code>outcomepooling()&lt;/code> does not apply).&lt;/li>
&lt;li>&lt;code>method(reg)&lt;/code> fits linear regressions for untreated &lt;strong>outcome changes&lt;/strong> $\Delta Y_{i,s,t}$, fitted separately per comparison block by default (&lt;code>outcomepooling(separate)&lt;/code>) or with shared duration-scaled covariate slopes across blocks (&lt;code>outcomepooling(pooled)&lt;/code>). It models outcome changes, not outcome levels.&lt;/li>
&lt;li>&lt;code>method(dr)&lt;/code> (default) combines both for doubly robust treatment adjustment.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="4-observation-model-selection-selectionconditional_mtar-logit-specifications-and-poolings">4. Observation-Model Selection (&lt;code>selection(conditional_mtar)&lt;/code>), Logit Specifications, and Poolings&lt;/h2>
&lt;p>When outcome missingness depends on covariates that also drive untreated outcome changes, &lt;code>selection(none)&lt;/code> can be biased: the units observed at both dates then over-represent strata with steeper or flatter trends, so their mean change no longer represents that of the cohort. &lt;code>selection(conditional_mtar)&lt;/code> adjusts for this with a model of observation.&lt;/p>
&lt;h3 id="direct-pair-logit-vs-independent-period-logit">Direct Pair Logit vs. Independent Period Logit&lt;/h3>
&lt;p>Under &lt;code>selmethod(ipw)&lt;/code> (the default), &lt;code>cdid&lt;/code> estimates pair observation probabilities $q_{g,s,t}(Z) = \Pr(R_{is}=1, R_{it}=1 \mid G_i=g, Z_i)$ using one of two logit families:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>&lt;code>selmodel(pair_logit)&lt;/code> (default)&lt;/strong>: Directly models the joint indicator $R_{is} R_{it}$ for each pair $(s,t)$.&lt;/li>
&lt;li>&lt;strong>&lt;code>selmodel(independent_period_logit)&lt;/code>&lt;/strong>: Models marginal date observation probabilities $\pi_{g,t}(Z) = \Pr(R_{it}=1 \mid G_i=g, Z_i)$ and forms $q_{g,s,t}(Z) = \pi_{g,s}(Z),\pi_{g,t}(Z)$.&lt;/li>
&lt;/ol>
&lt;p>&lt;strong>When both agree vs. when &lt;code>independent_period_logit&lt;/code> fails&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>If observation indicators are independent across dates conditional on a binary predictor and each probability model is saturated in that predictor, the two specifications can both be correct. The simulated data also make observation depend on the continuous &lt;code>z_sel&lt;/code> and include units observed once or never. Section 4a omits &lt;code>z_sel&lt;/code>, so it compares two specifications without implying that either is correct. A product of date logits need not have a linear pair-logit form.&lt;/li>
&lt;li>&lt;strong>Do not use &lt;code>selmodel(independent_period_logit)&lt;/code>&lt;/strong> when units are observed in rotating two-date windows (&lt;code>CDID_DEMO_MISS_LAW = &amp;quot;rotating_window&amp;quot;&lt;/code>), staggered entry/exit panels, or absorbing dropout. In those designs, observing a unit at date $s$ strongly predicts whether it can be observed at date $t$, violating conditional independence between dates even when marginal date probabilities are well-behaved. Use &lt;code>selmodel(pair_logit)&lt;/code> instead.&lt;/li>
&lt;/ul>
&lt;h3 id="selection-poolings-selpooling-and-separate-covariates-covars-vs-selcovars">Selection Poolings (&lt;code>selpooling&lt;/code>) and Separate Covariates (&lt;code>covars&lt;/code> vs. &lt;code>selcovars&lt;/code>)&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>&lt;code>selpooling(separate|within_cohort|across_cohorts)&lt;/code>&lt;/strong>:
&lt;ul>
&lt;li>&lt;code>separate&lt;/code> (default) fits unrestricted parameters for each cohort and pair (or date).&lt;/li>
&lt;li>&lt;code>within_cohort&lt;/code> and &lt;code>across_cohorts&lt;/code> pool slope parameters across transitions or across cohorts. More pooled $q$ models impose additional parametric restrictions to stabilize estimation in sparse cells; they do &lt;strong>not&lt;/strong> automatically produce better estimates when cell-level support is already sufficient.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Separate outcome and selection covariates&lt;/strong>: Use &lt;code>covars()&lt;/code> for covariates $X$ entering the treatment/outcome-change model and &lt;code>selcovars()&lt;/code> for covariates $Z$ entering the observation model (along with &lt;code>framecovars()&lt;/code> and &lt;code>frameselcovars()&lt;/code> when using &lt;code>frame()&lt;/code>):&lt;/li>
&lt;/ul>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(period) gvar(first_treat) ///
covars(i.x_bin c.x_cont) ///
selection(conditional_mtar) selmodel(pair_logit) selpooling(separate) ///
selcovars(i.x_bin c.x_cont c.z_sel) ///
frame(cdid_pop) frameivar(id) framegvar(first_treat) ///
framecovars(x_bin x_cont) frameselcovars(x_bin x_cont z_sel) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="5-pure-outcome-change-imputation-vs-augmented-correction-selmethod">5. Pure Outcome-Change Imputation vs. Augmented Correction (&lt;code>selmethod&lt;/code>)&lt;/h2>
&lt;p>In addition to inverse pair-observation probability weighting (&lt;code>selmethod(ipw)&lt;/code>), &lt;code>cdid&lt;/code> supports two regression-based observation corrections under &lt;code>selection(conditional_mtar)&lt;/code> (Section 5):&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Pure outcome-change imputation (&lt;code>selmethod(imputation)&lt;/code>)&lt;/strong>:
Imputes missing within-cohort outcome changes $\Delta Y_{i,s,t}$ over the cohort population using linear outcome-change regressions controlled by &lt;code>imppooling(separate|within_cohort|across_cohorts)&lt;/code>. Because no pair-observation logit is fitted under pure imputation, &lt;code>selmodel()&lt;/code>, &lt;code>selpooling()&lt;/code>, and &lt;code>selcovars()&lt;/code> do not apply and are listed in &lt;code>e(inactive_options)&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Augmented observation correction (&lt;code>selmethod(dr)&lt;/code>)&lt;/strong>:
Requires &lt;code>selection(conditional_mtar)&lt;/code> with &lt;code>seluniverse(F)&lt;/code> (and no &lt;code>selrho()&lt;/code>) and works with &lt;code>method(ipw|reg|dr)&lt;/code>; &lt;code>method(custom)&lt;/code> is not supported. It combines inverse pair-observation probability weighting (&lt;code>selmodel()&lt;/code>, &lt;code>selpooling()&lt;/code>, &lt;code>selcovars()&lt;/code>) with linear outcome-change imputation (&lt;code>imppooling()&lt;/code>) so cohort mean-change moments remain consistent if either the pair-observation model or the outcome-change imputation model is correctly specified (and doubly robust in both layers when paired with &lt;code>method(dr)&lt;/code>).&lt;/li>
&lt;/ol>
&lt;pre>&lt;code class="language-stata">* 5a. Pure outcome-change imputation (`selmethod(imputation)`)
cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) selection(conditional_mtar) ///
selmethod(imputation) imppooling(separate) ///
biters($CDID_DEMO_BITERS)
* 5b. Doubly robust observation + treatment adjustment (`selmethod(dr)` with `method(dr)`)
cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) selection(conditional_mtar) ///
selmethod(dr) selmodel(pair_logit) selpooling(separate) ///
selcovars(i.x_bin c.x_cont c.z_sel) imppooling(separate) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="6-clustering-and-sampling-weights">6. Clustering and sampling weights&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Clustering (&lt;code>cluster(varname)&lt;/code> / &lt;code>framecluster(name)&lt;/code>)&lt;/strong>: Sums the unit influence functions within clusters to compute the analytical covariance &lt;code>e(V)&lt;/code>, multiplier bootstrap standard errors &lt;code>e(se)&lt;/code>, simultaneous confidence bands &lt;code>e(ci)&lt;/code>, and Wald tests. &lt;strong>Clustering affects inference only&lt;/strong>: it changes neither the GMM weighting matrix nor the point estimates.&lt;/li>
&lt;li>&lt;strong>Sampling weights (&lt;code>wvar(varname)&lt;/code> / &lt;code>[iweight=...]&lt;/code> and &lt;code>fixweights()&lt;/code>)&lt;/strong>: When panel weights vary across calendar dates, &lt;code>fixweights(first_period)&lt;/code> uses each unit&amp;rsquo;s weight at the first study date, where it must be supplied, while &lt;code>fixweights(base_period)&lt;/code> uses the weight at each target cohort&amp;rsquo;s reference date:&lt;/li>
&lt;/ul>
&lt;pre>&lt;code class="language-stata">cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
wvar(w_tv) fixweights(first_period) cluster(cluster_id) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="7-postestimation-aggregations-estat-and-pointwise-vs-simultaneous-bands">7. Postestimation Aggregations (&lt;code>estat&lt;/code>) and Pointwise vs. Simultaneous Bands&lt;/h2>
&lt;p>After &lt;code>cdid&lt;/code> (unless &lt;code>noinffunc&lt;/code> was specified), &lt;code>estat&lt;/code> computes four aggregations from the stored results, without using the data in memory or refitting any model (Section 7):&lt;/p>
&lt;ul>
&lt;li>&lt;code>estat simple&lt;/code>: Overall weighted average of post-treatment $ATT(g,t)$ cells.&lt;/li>
&lt;li>&lt;code>estat group&lt;/code>: Cohort-specific average treatment effects across post-treatment periods, plus an overall cohort-weighted ATT.&lt;/li>
&lt;li>&lt;code>estat dynamic&lt;/code>: Event-study aggregation by relative event time $e = t - g$.&lt;/li>
&lt;li>&lt;code>estat calendar&lt;/code>: Calendar-period aggregation across cohorts treated by date $t$.&lt;/li>
&lt;/ul>
&lt;h3 id="inference-settings-event-windows-and-confidence-bands">Inference settings, event windows and confidence bands&lt;/h3>
&lt;p>By default, &lt;code>estat&lt;/code> uses the &lt;code>bstrap&lt;/code>, &lt;code>cband&lt;/code>, &lt;code>biters&lt;/code>, &lt;code>level&lt;/code> and &lt;code>cluster&lt;/code> settings of the &lt;code>cdid&lt;/code> estimation. You can customize event-study windows and compare simultaneous confidence bands (&lt;code>cband(1)&lt;/code>) against pointwise intervals (&lt;code>cband(0)&lt;/code>):&lt;/p>
&lt;pre>&lt;code class="language-stata">estat simple
estat group
estat calendar
estat dynamic
* 7b. Dynamic event-study selectors (`mine`, `maxe`, `balancee`, `narm`)
estat dynamic, mine(-2) maxe(2) narm
estat dynamic, balancee(1) narm
* 7c. Comparing simultaneous confidence bands (`cband(1)`) vs pointwise intervals (`cband(0)`)
estat dynamic, cband(1)
estat dynamic, cband(0)
&lt;/code>&lt;/pre>
&lt;p>&lt;code>e(se)&lt;/code> holds the reported standard errors (from the multiplier bootstrap when &lt;code>bstrap(1)&lt;/code>), whereas &lt;code>e(V)&lt;/code> and &lt;code>e(analytic_se)&lt;/code> hold the analytical covariance and standard errors.&lt;/p>
&lt;hr>
&lt;h2 id="8-pretrend-tests-the-wald-test-and-cdid_pretest">8. Pretrend tests: the Wald test and &lt;code>cdid_pretest&lt;/code>&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> provides two pretrend tests (Section 8):&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Joint Wald test (&lt;code>e(wald_*)&lt;/code>)&lt;/strong>:
Computed by &lt;code>cdid&lt;/code> from all requested pretreatment cells other than reference cells, and not computed if any of them or their joint covariance is unavailable, using the analytical covariance &lt;code>e(V)&lt;/code>. Stored in &lt;code>e(wald_statistic)&lt;/code>, &lt;code>e(wald_df)&lt;/code>, &lt;code>e(wald_p)&lt;/code>, and &lt;code>e(wald_status)&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Conditional Cramér-von Mises test (&lt;code>cdid_pretest&lt;/code>)&lt;/strong>:
Tests conditional parallel trends over the covariate distribution with a Cramér-von Mises (CvM) statistic and a multiplier bootstrap. &lt;code>cdid_pretest&lt;/code> returns its results in &lt;code>r()&lt;/code>, uses &lt;code>method(ipw)&lt;/code> by default (unlike &lt;code>cdid&lt;/code>, whose default is &lt;code>method(dr)&lt;/code>), and leaves the current &lt;code>e()&lt;/code> results unchanged:&lt;/li>
&lt;/ol>
&lt;pre>&lt;code class="language-stata">* 8a. The pretrend Wald test stored in `e()`
cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) biters($CDID_DEMO_BITERS)
display as text &amp;quot;Wald test status: &amp;quot; as result &amp;quot;`e(wald_status)'&amp;quot; ///
as text &amp;quot; chi2(&amp;quot; as result e(wald_df) as text &amp;quot;) = &amp;quot; as result %9.4f e(wald_statistic) ///
as text &amp;quot; p = &amp;quot; as result %6.4f e(wald_p)
* 8b. Conditional pretrend CvM test (`cdid_pretest`)
* The default treatment adjustment is `ipw`; `e()` from `cdid` is unchanged.
cdid_pretest y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
biters($CDID_DEMO_BITERS)
return list
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="9-diagnostics-graphs-and-datasets">9. Diagnostics, graphs and datasets&lt;/h2>
&lt;p>&lt;code>cdid_diagnostics&lt;/code> summarizes the study population, the comparisons available, the model and the inference behind the current results; with &lt;code>detail&lt;/code>, it also lists the unavailable cells. Quantities that were not stored with the results are reported as not retained, never as zero. The test of &lt;code>cdid_pretest&lt;/code> is reported by that command, not by &lt;code>cdid_diagnostics&lt;/code>.&lt;/p>
&lt;p>&lt;code>cdid_plot&lt;/code> graphs the current results. After &lt;code>estat dynamic&lt;/code>, it graphs the event study; &lt;code>cdid_plot, cells&lt;/code> graphs the group-time estimates instead. Graph options such as &lt;code>title()&lt;/code> can be added. &lt;code>saving()&lt;/code> writes a &lt;code>.gph&lt;/code> file, &lt;code>export()&lt;/code> writes the graph in another format with &lt;code>graph export&lt;/code>, and &lt;code>plotdata()&lt;/code> saves the plotted values as a dataset. Existing files are replaced only with &lt;code>replace&lt;/code>.&lt;/p>
&lt;p>&lt;code>cdid_export&lt;/code> saves the stored results as a Stata dataset, with &lt;code>type(cells|aggregate|units|influence|summary)&lt;/code>; &lt;code>cells&lt;/code> is the default. It does not refit or draw random numbers. After &lt;code>estat&lt;/code>, &lt;code>type(cells)&lt;/code> still saves every group-time cell, and &lt;code>type(aggregate)&lt;/code> saves the aggregation. Reported and analytical standard errors are saved in separate variables. After an aggregation in ordinary mode, the pointwise intervals of the group-time cells can be missing; the reported intervals are always saved.&lt;/p>
&lt;pre>&lt;code class="language-stata">* 9a. Diagnostics
cdid_diagnostics
cdid_diagnostics, detail
* 9b. Export cell and summary tables to temporary files and inspect them in frames
* cdid_export accepts temporary file names as they are; Stata erases the files
* when the do-file ends. Files are kept on disk only in 9c and Section 10.
tempfile demo_cells_dta demo_summary_dta
cdid_export using &amp;quot;`demo_cells_dta'&amp;quot;, type(cells)
capture frame drop demo_cells_tbl
frame create demo_cells_tbl
frame demo_cells_tbl: use &amp;quot;`demo_cells_dta'&amp;quot;
frame demo_cells_tbl: list in 1/10, abbrev(16)
cdid_export using &amp;quot;`demo_summary_dta'&amp;quot;, type(summary)
capture frame drop demo_summary_tbl
frame create demo_summary_tbl
frame demo_summary_tbl: use &amp;quot;`demo_summary_dta'&amp;quot;
frame demo_summary_tbl: list, abbrev(20)
* 9c. Graphs and datasets kept on disk (requires CDID_DEMO_OUTDIR)
if `&amp;quot;$CDID_DEMO_OUTDIR&amp;quot;' != &amp;quot;&amp;quot; {
local repopt = cond($CDID_DEMO_REPLACE == 1, &amp;quot;replace&amp;quot;, &amp;quot;&amp;quot;)
cdid_plot, title(&amp;quot;Group-Time ATT Estimates&amp;quot;) ///
saving(&amp;quot;$CDID_DEMO_OUTDIR/cdid_group_time.gph&amp;quot;) `repopt'
estat dynamic
cdid_plot, title(&amp;quot;Dynamic Event-Study ATT&amp;quot;) ///
saving(&amp;quot;$CDID_DEMO_OUTDIR/cdid_dynamic.gph&amp;quot;) `repopt'
cdid_export using &amp;quot;$CDID_DEMO_OUTDIR/cdid_dynamic.dta&amp;quot;, type(aggregate) `repopt'
}
&lt;/code>&lt;/pre>
&lt;p>Section 9 writes temporary datasets and opens them in frames. Stata erases the files at the end of the do-file. Set &lt;code>CDID_DEMO_OUTDIR&lt;/code> to an existing folder to keep the &lt;code>.gph&lt;/code> and &lt;code>.dta&lt;/code> files. For CSV or other formats, use Stata&amp;rsquo;s export commands on the saved dataset.&lt;/p>
&lt;hr>
&lt;h2 id="10-saving-and-loading-results-saving-cdid_load-cdid_pretest_load">10. Saving and loading results (&lt;code>saving()&lt;/code>, &lt;code>cdid_load&lt;/code>, &lt;code>cdid_pretest_load&lt;/code>)&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code>, &lt;code>estat&lt;/code> and &lt;code>cdid_pretest&lt;/code> accept &lt;code>saving(filename)&lt;/code>, which writes the complete results to a file. &lt;code>saving()&lt;/code> never overwrites an existing file.&lt;/p>
&lt;p>You can restore saved results in a later Stata session, even when memory is empty or holds an unrelated dataset, using &lt;code>cdid_load&lt;/code> and &lt;code>cdid_pretest_load&lt;/code> (Section 10):&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid_demo_init
if `&amp;quot;$CDID_DEMO_OUTDIR&amp;quot;' != &amp;quot;&amp;quot; {
local cells_file &amp;quot;$CDID_DEMO_OUTDIR/demo_cells.cdidstate&amp;quot;
local dyn_file &amp;quot;$CDID_DEMO_OUTDIR/demo_dynamic.cdidstate&amp;quot;
local pt_file &amp;quot;$CDID_DEMO_OUTDIR/demo_pretest.cdidpt&amp;quot;
}
else {
tempfile cells_file dyn_file pt_file
}
* 10a. Save the group-time results, the event study, and the pretrend test
cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
cluster(cluster_id) biters($CDID_DEMO_BITERS) saving(&amp;quot;`cells_file'&amp;quot;)
estat dynamic, saving(&amp;quot;`dyn_file'&amp;quot;)
cdid_pretest y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
biters($CDID_DEMO_BITERS) saving(&amp;quot;`pt_file'&amp;quot;)
* 10b. Replace the data with a small unrelated dataset and load the results
preserve
clear
set obs 5
generate byte unrelated_x = _n
* Load the group-time results and use `estat` and `cdid_diagnostics`
cdid_load using &amp;quot;`cells_file'&amp;quot;
count if e(sample)
assert r(N) == 0
display as text &amp;quot;e(sample_scope): &amp;quot; as result &amp;quot;`e(sample_scope)'&amp;quot;
display as text &amp;quot;e(cmdline): &amp;quot; as result `&amp;quot;`e(cmdline)'&amp;quot;'
cdid_diagnostics
estat group
* Load the event study
cdid_load using &amp;quot;`dyn_file'&amp;quot;
* Load with `posting(state)` (complete results, without e(b) and e(V))
cdid_load using &amp;quot;`cells_file'&amp;quot;, posting(state)
display as text &amp;quot;Coefficients posted with posting(state): &amp;quot; as result e(N_posted)
* Load the pretrend test results (e() is unchanged)
cdid_pretest_load using &amp;quot;`pt_file'&amp;quot;
return list
restore
* ==============================================================================
&lt;/code>&lt;/pre>
&lt;h3 id="what-loading-does">What loading does&lt;/h3>
&lt;ul>
&lt;li>&lt;strong>No re-estimation&lt;/strong>: &lt;code>cdid_load&lt;/code> restores in &lt;code>e()&lt;/code> exactly the saved estimates, standard errors &lt;code>e(se)&lt;/code>, covariance &lt;code>e(V)&lt;/code>, intervals and bands, and group-time and unit tables; &lt;code>cdid_pretest_load&lt;/code> restores the test results in &lt;code>r()&lt;/code>. They draw no random numbers; &lt;code>c(rngstate)&lt;/code> and &lt;code>c(sortrngstate)&lt;/code> are unchanged.&lt;/li>
&lt;li>&lt;strong>Command line.&lt;/strong> &lt;code>e(cmdline)&lt;/code> holds the original &lt;code>cdid&lt;/code> command of the saved fit or aggregation.&lt;/li>
&lt;li>&lt;strong>Size limits&lt;/strong>: &lt;code>posting(matrix)&lt;/code>, the default, posts the results as matrices and fails with &lt;code>r(908)&lt;/code> when they exceed &lt;code>c(max_matdim)&lt;/code>; &lt;code>posting(state)&lt;/code> loads the complete results without posting &lt;code>e(b)&lt;/code> and &lt;code>e(V)&lt;/code> (&lt;code>cdid_pretest_load&lt;/code> then requires &lt;code>store(name)&lt;/code>).&lt;/li>
&lt;li>&lt;strong>Errors&lt;/strong>: damaged files and files of the wrong type (for example, a file saved by &lt;code>cdid&lt;/code> given to &lt;code>cdid_pretest_load&lt;/code>) cause error &lt;code>r(498)&lt;/code>; the data and the current results are then unchanged.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;h2 id="11-common-errors">11. Common errors&lt;/h2>
&lt;p>Section 11 shows errors caused by incomplete specifications or insufficient data. Each command stops with an error message and leaves the data and the current results unchanged:&lt;/p>
&lt;pre>&lt;code class="language-stata">* 11a. `ptassumption(all)` without `ptstart(#)` (rc = 459)
capture noisily cdid y x_bin, ivar(id) time(period) gvar(first_treat) ptassumption(all)
assert _rc == 459
* 11b. `selmethod(dr)` with `selection(none)` (rc = 459)
capture noisily cdid y x_bin, ivar(id) time(period) gvar(first_treat) ///
selection(none) selmethod(dr)
assert _rc == 459
* 11c. Insufficient support: restricting to a single calendar period leaves no (s, t) pairs
capture noisily cdid y x_bin if period == 1, ivar(id) time(period) gvar(first_treat)
assert _rc != 0
* 11d. Wrong file type: a file saved by `cdid` given to `cdid_pretest_load` (rc = 498)
tempfile tmp_cell_state
cdid y x_bin, ivar(id) time(period) gvar(first_treat) noinffunc saving(&amp;quot;`tmp_cell_state'&amp;quot;)
capture noisily cdid_pretest_load using &amp;quot;`tmp_cell_state'&amp;quot;
assert _rc == 498
&lt;/code>&lt;/pre>
&lt;hr>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>Bellégo, C., Benatia, D., &amp;amp; Dortet-Bernadet, V. (2025). &lt;em>The Chained Difference-in-Differences&lt;/em>. Journal of Econometrics, 248, 105783. &lt;a href="https://doi.org/10.1016/j.jeconom.2024.105783" target="_blank" rel="noopener">https://doi.org/10.1016/j.jeconom.2024.105783&lt;/a>&lt;/li>
&lt;li>Callaway, B., &amp;amp; Sant&amp;rsquo;Anna, P. H. C. (2021). &lt;em>Difference-in-Differences with multiple time periods&lt;/em>. Journal of Econometrics, 225(2), 200-230. &lt;a href="https://doi.org/10.1016/j.jeconom.2020.12.001" target="_blank" rel="noopener">https://doi.org/10.1016/j.jeconom.2020.12.001&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a>&lt;/p></description></item><item><title>How to compare precision</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/precision/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/precision/</guid><description>&lt;p>A smaller standard error does not by itself establish a better estimator. Before comparing chained and ordinary mode, control groups, parallel trends choices or corrections for missing outcomes, match the target population and parameter, then state the assumptions that justify each fit. Balance alone decides neither validity nor a precision ranking. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/">Moving from did&lt;/a> explains how to choose between the two estimation modes.&lt;/p>
&lt;p>This page explains the covariance of chained estimates and the diagnostics that help compare precision. It reports no simulation results. The examples elsewhere in this guide show single estimations; they do not compare precision over repeated samples.&lt;/p>
&lt;h2 id="more-comparisons-do-not-mean-independent-information">More comparisons do not mean independent information&lt;/h2>
&lt;p>Chained estimation combines two-date comparisons. If a vector of link estimates has covariance matrix $\Sigma$ and its coefficients $a$ are fixed, the variance of the linear combination is $a'\Sigma a$. The off-diagonal covariances matter as much as the individual link variances. This is an exact identity for fixed coefficients. Feasible GMM estimates its weights from the same data: inserting fitted, data-dependent coefficients does not give an exact unconditional finite-sample variance identity. Under the appropriate GMM regularity conditions, a first-order calculation uses the limiting combination and complete influence functions. The package&amp;rsquo;s inference follows its complete influence functions, rather than treating fitted weights as an exact finite-sample variance formula.&lt;/p>
&lt;p>For the same unit, consecutive changes telescope:&lt;/p>
&lt;p>$$
(Y_{i,4}-Y_{i,3})+(Y_{i,3}-Y_{i,2})=Y_{i,4}-Y_{i,2}.
$$&lt;/p>
&lt;p>The shared intermediate outcome cancels. If time-specific measurement errors are mutually independent, their contribution to the covariance of these adjacent changes is minus the variance of the shared error. The total covariance need not be negative: serial dependence, heterogeneous trends and other shared components also matter. With different observed units or weights at each link, estimated link averages need not telescope.&lt;/p>
&lt;p>In a balanced panel, chained estimates agree with ordinary DiD up to rounding under the following settings: built-in IPW, no covariates, no correction for missing outcomes, never treated controls, weights fixed across comparisons, PT-post, and matching anticipation and reporting settings. Splitting the same units' long changes into consecutive steps adds comparison rows without independent information. This equality of point estimates does not extend to every standard error, band or aggregation. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/#when-chained-and-ordinary-estimates-should-agree">the precise comparison&lt;/a>.&lt;/p>
&lt;h2 id="what-gmm-weighting-and-standard-errors-measure">What GMM weighting and standard errors measure&lt;/h2>
&lt;p>Overlapping comparison paths can make the moment covariance singular even when an ATT is supported. Lack of support is a different issue: if the available comparisons and trend restrictions cannot recover a cell, weighting cannot make it available. Inspect support and reasons with &lt;code>cdid_diagnostics, detail&lt;/code> or the &lt;code>type(cells)&lt;/code> export.&lt;/p>
&lt;p>With &lt;code>gmmweighting(optimal)&lt;/code>, feasible two-step GMM uses an estimated moment covariance. &lt;code>cdid&lt;/code> first removes comparisons that are exactly redundant. With &lt;code>gmmcovariance(tikhonov)&lt;/code>, it then adds a ridge proportional to the trace when the remaining covariance needs regularization; a covariance that is exactly zero has a separate least-squares rule. Regularization affects the weighting only: it adds no identifying information and does not guarantee a gain in precision. &lt;code>cdid_diagnostics&lt;/code> reports how the covariance was handled; &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/">GMM weighting&lt;/a> gives the rules.&lt;/p>
&lt;p>The inverse weighting matrix is not the reported estimator covariance. With influence functions computed:&lt;/p>
&lt;ul>
&lt;li>The influence functions have one row per unit of the study population, including units without an observed change.&lt;/li>
&lt;li>&lt;code>e(V)&lt;/code> stores analytical estimator covariance, while &lt;code>e(V_asymptotic) = e(N_full) * e(V)&lt;/code>.&lt;/li>
&lt;li>&lt;code>e(analytic_se)&lt;/code> is the square root of the diagonal of &lt;code>e(V)&lt;/code>. &lt;code>e(se)&lt;/code> holds the reported standard errors, analytical or from the multiplier bootstrap, so it need not equal &lt;code>e(analytic_se)&lt;/code>.&lt;/li>
&lt;/ul>
&lt;p>The influence functions account for the estimation of the adjustment models and, in aggregations, of the cohort shares. Clustering sums their rows within clusters for inference; it does not change the unit-based GMM weights or point estimates. Check the inference settings with &lt;code>cdid_diagnostics&lt;/code>, and compare pointwise intervals with pointwise intervals, and simultaneous bands with bands of the same aggregation. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/inference/">Inference&lt;/a> and the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/#uncertainty">results reference&lt;/a> explain the endpoints and &lt;code>estat&lt;/code> outputs.&lt;/p>
&lt;h2 id="incomplete-panels-match-the-population-and-sampling-conditions">Incomplete panels: match the population and sampling conditions&lt;/h2>
&lt;p>Complete-case analysis, repeated cross sections and chained changes each have settings where they are valid. Their standard errors answer a common precision question only when their targets and assumptions align.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Approach&lt;/th>
&lt;th>What to check before comparing precision&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Complete-case balancing&lt;/td>
&lt;td>It uses units observed at every date. Their ATT can differ from the full population ATT when observation relates to heterogeneous effects. The targets can coincide under suitable representativeness conditions; a rotating panel may contain no complete cases.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Outcome-level RCS comparisons&lt;/td>
&lt;td>Each date&amp;rsquo;s sample must satisfy the level-sampling conditions. Changing composition in an unobserved fixed component can invalidate that comparison even when observed within-unit changes remain representative. Fixed differences alone do not invalidate representative RCS sampling.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Chained changes&lt;/td>
&lt;td>The observed changes, possibly after correction, must represent the study population under the assumptions chosen. Overlapping pairs can identify effects without any complete unit; when few units link the dates, estimates can still be imprecise.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Ordinary mode with &lt;code>allowunbalanced&lt;/code> uses the repeated cross-section estimators while clustering by unit. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/">Moving from did&lt;/a> describes the options, and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a> states the chained conditions.&lt;/p>
&lt;h2 id="restrictions-can-change-information-and-robustness">Restrictions can change information and robustness&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Choice&lt;/th>
&lt;th>What can change, holding the population target fixed&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Never treated versus not yet treated controls&lt;/td>
&lt;td>Under not-yet-treated parallel trends and overlap, chained estimation can use the same pair of dates again with other control groups at later horizons. Combining these comparisons by GMM can change estimates and uncertainty even with complete outcomes. More valid comparisons do not guarantee a gain in every finite sample.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>PT-post versus PT-all&lt;/td>
&lt;td>Credible extra untreated-trend restrictions from the chosen &lt;code>ptstart()&lt;/code> can add identification or precision. False restrictions can bias estimates; neither bias nor a gain follows from the option label alone. PT-all may add no restriction in a particular calendar. &lt;code>baseperiod()&lt;/code> separately controls how pretreatment cells are reported.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Treatment OR or DR (&lt;code>outcomepooling()&lt;/code>)&lt;/td>
&lt;td>Default &lt;code>outcomepooling(separate)&lt;/code> fits comparison-block-specific counterfactual change slopes $\beta_b$, whereas &lt;code>outcomepooling(pooled)&lt;/code> imposes one shared slope vector $\beta$ across comparison blocks. Credible pooling can share information; unjustified pooling can invalidate the outcome regression. DR remains consistent if the propensity model is correct, under the other required conditions.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Observation or imputation pooling&lt;/td>
&lt;td>&lt;code>selpooling()&lt;/code> shares coefficients of observation-probability models; &lt;code>imppooling()&lt;/code> shares regressions of actual cohort changes, including treatment effects. Neither argument controls &lt;code>outcomepooling()&lt;/code> in treatment OR/DR. Their distinct restrictions require justification.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Small pair probabilities can amplify observation weights; rare links and weak covariate support can worsen uncertainty. Neither a large unit table nor a short chain alone determines precision. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/">Robustness&lt;/a> separates the model-correctness alternatives, and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/">Parallel trends&lt;/a> explains which restrictions are active.&lt;/p>
&lt;h2 id="read-a-fit-before-making-a-ranking">Read a fit before making a ranking&lt;/h2>
&lt;p>Use &lt;code>e(N_full)&lt;/code>, the dataset written by &lt;code>cdid_export, type(cells)&lt;/code> and &lt;code>cdid_diagnostics&lt;/code> to compare the population, target cells, support, restrictions and inference actually used. An unavailable effect has no precision ranking. An estimated standard error differs from the standard deviation of estimates over repeated samples. Bias, RMSE and coverage can be assessed only by simulation, with known population values, every replication counted (including those that fail), and Monte Carlo standard errors.&lt;/p>
&lt;p>&lt;code>workspace()&lt;/code> limits the memory used for the main numerical arrays, and &lt;code>workcap()&lt;/code> optionally limits the number of operations; neither limits the total memory or computation time of Stata.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 5 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/identification/">Identify effects when the observed units change composition&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/">Prepare your panel and unit table&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Identify effects when the observed units change composition</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/identification/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/identification/</guid><description>&lt;p>This example builds a small rotating panel in which the treated units observed at each date have a different mix of a fixed, unobserved unit component. Outcome changes within the same unit still identify the treatment effects, while comparisons of mean outcome levels across dates do not. The reasoning is the argument about mean pair changes in &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/#forward-telescoping-across-intermediate-dates">Estimate treatment effects from incomplete panels&lt;/a>, applied to one concrete design.&lt;/p>
&lt;h2 id="question">Question&lt;/h2>
&lt;p>A study follows units over five dates. Units in cohort 3 are first treated at date 3, and the others are never treated. Each unit is observed at exactly two consecutive dates. Among treated units, those with a high fixed component tend to be observed early and those with a low one late. Write ATT(3,t) for the average treatment effect of cohort 3 at date t. Can the changes observed within units identify ATT(3,3), ATT(3,4) and ATT(3,5) when the observed treated units differ in composition from date to date?&lt;/p>
&lt;h2 id="the-design">The design&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Cohort.&lt;/strong> $G$ is 0 or 3, each with probability 1/2.&lt;/li>
&lt;li>&lt;strong>Fixed component.&lt;/strong> $\alpha$ is $-1$ or $+1$, each with probability 1/2, independently of $G$. The estimators never see $\alpha$, and no covariate is supplied.&lt;/li>
&lt;li>&lt;strong>Untreated outcomes.&lt;/strong> $Y_t(0) = \alpha + 0.1,t + \varepsilon_t$. The $\varepsilon_t$ have mean zero, are independent across dates and are independent of $G$, $\alpha$ and observation.&lt;/li>
&lt;li>&lt;strong>Effect.&lt;/strong> Let $\tau_t = 1$ when $G = 3$ and $t \ge 3$, and $\tau_t = 0$ otherwise. The actual outcome is $Y_t = Y_t(0) + \tau_t$, so every treated unit gains exactly 1 from date 3 onward and nothing earlier. ATT(3,3), ATT(3,4) and ATT(3,5) all equal 1, for the simulated units and for the population the design describes.&lt;/li>
&lt;li>&lt;strong>Observation.&lt;/strong> Each unit is observed in one window $W$ of two consecutive dates, (1,2), (2,3), (3,4) or (4,5), drawn given $G$ and $\alpha$ with the probabilities in Table 1.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Table 1. Window probabilities given cohort and fixed component (population algebra)&lt;/strong>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Units&lt;/th>
&lt;th>Share of units&lt;/th>
&lt;th>(1,2)&lt;/th>
&lt;th>(2,3)&lt;/th>
&lt;th>(3,4)&lt;/th>
&lt;th>(4,5)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>$G = 0$, either value of $\alpha$&lt;/td>
&lt;td>1/2&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.25&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$G = 3$, $\alpha = +1$&lt;/td>
&lt;td>1/4&lt;/td>
&lt;td>0.40&lt;/td>
&lt;td>0.30&lt;/td>
&lt;td>0.20&lt;/td>
&lt;td>0.10&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$G = 3$, $\alpha = -1$&lt;/td>
&lt;td>1/4&lt;/td>
&lt;td>0.10&lt;/td>
&lt;td>0.20&lt;/td>
&lt;td>0.30&lt;/td>
&lt;td>0.40&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$G = 3$, both values together&lt;/td>
&lt;td>1/2&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.25&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Each window contains treated and never treated units with both values of $\alpha$ with positive probability, and each window holds a quarter of each cohort. No unit is observed at all five dates: every unit has exactly two observed outcomes.&lt;/p>
&lt;p>Let $R_t = 1$ when date $t$ lies in the unit&amp;rsquo;s window. Write $p_t^{+}$ and $p_t^{-}$ for the probability that $R_t = 1$ in cohort 3 when $\alpha = +1$ and when $\alpha = -1$; each is the sum of the probabilities of the windows that contain $t$. Because the two values of $\alpha$ have equal mass in cohort 3,&lt;/p>
&lt;p>$$m_t = E[\alpha \mid G = 3, R_t = 1] = \frac{p_t^{+} - p_t^{-}}{p_t^{+} + p_t^{-}}.$$&lt;/p>
&lt;p>&lt;strong>Table 2. Observation and the mean fixed component by date (population algebra)&lt;/strong>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Quantity&lt;/th>
&lt;th>$t = 1$&lt;/th>
&lt;th>$t = 2$&lt;/th>
&lt;th>$t = 3$&lt;/th>
&lt;th>$t = 4$&lt;/th>
&lt;th>$t = 5$&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>$p_t^{+}$&lt;/td>
&lt;td>0.4&lt;/td>
&lt;td>0.7&lt;/td>
&lt;td>0.5&lt;/td>
&lt;td>0.3&lt;/td>
&lt;td>0.1&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$p_t^{-}$&lt;/td>
&lt;td>0.1&lt;/td>
&lt;td>0.3&lt;/td>
&lt;td>0.5&lt;/td>
&lt;td>0.7&lt;/td>
&lt;td>0.4&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$P(R_t = 1 \mid G = 3) = P(R_t = 1 \mid G = 0)$&lt;/td>
&lt;td>0.25&lt;/td>
&lt;td>0.5&lt;/td>
&lt;td>0.5&lt;/td>
&lt;td>0.5&lt;/td>
&lt;td>0.25&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$m_t = E[\alpha \mid G = 3, R_t = 1]$&lt;/td>
&lt;td>0.6&lt;/td>
&lt;td>0.4&lt;/td>
&lt;td>0&lt;/td>
&lt;td>$-0.4$&lt;/td>
&lt;td>$-0.6$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>$E[\alpha \mid G = 0, R_t = 1]$&lt;/td>
&lt;td>0&lt;/td>
&lt;td>0&lt;/td>
&lt;td>0&lt;/td>
&lt;td>0&lt;/td>
&lt;td>0&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The two cohorts are observed with the same probability at every date, so cohort 3 makes up half of the observed units at each date. What changes is the mix within cohort 3: its observed units have a mean $\alpha$ of 0.4 at date 2 and $-0.4$ at date 4.&lt;/p>
&lt;h2 id="why-changes-within-units-identify-the-effects">Why changes within units identify the effects&lt;/h2>
&lt;p>For a unit observed in window $(s, s+1)$, the fixed component cancels from its change:&lt;/p>
&lt;p>$$Y_{s+1} - Y_s = 0.1 + (\tau_{s+1} - \tau_s) + \varepsilon_{s+1} - \varepsilon_s.$$&lt;/p>
&lt;p>The change depends on the cohort, the dates and the noise, while the window depends only on the cohort and $\alpha$. Within each cohort, the units observed at both dates of a pair therefore have the cohort&amp;rsquo;s mean change,&lt;/p>
&lt;p>$$E[Y_{s+1} - Y_s \mid G, W = (s, s+1)] = E[Y_{s+1} - Y_s \mid G],$$&lt;/p>
&lt;p>even though they do not represent the cohort in levels. This mean condition is what &lt;code>selection(none)&lt;/code> requires, as described in &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/#without-an-observation-model-selectionnone-default">Handling missing outcomes&lt;/a>. Observation depends on $\alpha$, but $\alpha$ never enters a change, so no model of observation is needed.&lt;/p>
&lt;p>Write $D_{s,s+1}$ for the mean change of cohort 3 minus the mean change of the never treated units. Every mean change equals 0.1, except the change of cohort 3 from date 2 to date 3, which is 1.1. Hence $D_{1,2} = 0$, $D_{2,3} = 1$, $D_{3,4} = 0$ and $D_{4,5} = 0$.&lt;/p>
&lt;p>Untreated outcomes satisfy $Y_t(0) - Y_2(0) = 0.1,(t - 2) + \varepsilon_t - \varepsilon_2$ in both cohorts, so PT-post from reference date 2 holds, and there is no anticipation. The first link then identifies the effect, and the later links identify its increments:&lt;/p>
&lt;p>$$D_{2,3} = \text{ATT}(3,3) = 1, \qquad D_{3,4} = \text{ATT}(3,4) - \text{ATT}(3,3) = 0, \qquad D_{4,5} = \text{ATT}(3,5) - \text{ATT}(3,4) = 0.$$&lt;/p>
&lt;p>Summing the links gives $\text{ATT}(3,4) = D_{2,3} + D_{3,4} = 1$ and $\text{ATT}(3,5) = D_{2,3} + D_{3,4} + D_{4,5} = 1$. The four windows are the only pairs anyone is observed at, so chained difference in differences (chained DiD) can only combine these consecutive comparisons. The cell at date 2, reported before treatment, uses $D_{1,2}$.&lt;/p>
&lt;h2 id="why-comparisons-of-levels-do-not">Why comparisons of levels do not&lt;/h2>
&lt;p>An intercept-only repeated cross section (RCS) IPW estimator compares normalized means of outcome levels in each cohort and date arm. Its constant propensity odds cancel within each normalized control mean. In this design the population propensity is 1/2, away from the trimming threshold, so the population comparison for cell (3,t) with reference date 2 is&lt;/p>
&lt;p>$$\bigl(E[Y_t \mid G = 3, R_t = 1] - E[Y_2 \mid G = 3, R_2 = 1]\bigr) - \bigl(E[Y_t \mid G = 0, R_t = 1] - E[Y_2 \mid G = 0, R_2 = 1]\bigr).$$&lt;/p>
&lt;p>The common trend cancels, and the observed never treated units have a mean $\alpha$ of zero at every date, so for $t \ge 3$ this contrast equals $1 + m_t - m_2$, with $m_2 = 0.4$.&lt;/p>
&lt;p>&lt;strong>Table 3. What each comparison targets (population algebra)&lt;/strong>&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Cell&lt;/th>
&lt;th>Known value&lt;/th>
&lt;th>Chained links&lt;/th>
&lt;th>Comparison of observed levels&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Date 2, before treatment (dates 1 and 2)&lt;/td>
&lt;td>0&lt;/td>
&lt;td>$D_{1,2} = 0$&lt;/td>
&lt;td>$m_2 - m_1 = 0.4 - 0.6 = -0.2$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ATT(3,3)&lt;/td>
&lt;td>1&lt;/td>
&lt;td>$D_{2,3} = 1$&lt;/td>
&lt;td>$1 + (0 - 0.4) = 0.6$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ATT(3,4)&lt;/td>
&lt;td>1&lt;/td>
&lt;td>$1 + 0 = 1$&lt;/td>
&lt;td>$1 + (-0.4 - 0.4) = 0.2$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>ATT(3,5)&lt;/td>
&lt;td>1&lt;/td>
&lt;td>$1 + 0 + 0 = 1$&lt;/td>
&lt;td>$1 + (-0.6 - 0.4) = 0$&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Callaway and Sant&amp;rsquo;Anna&amp;rsquo;s repeated cross section setting assumes that the sample at each date represents the population at that date and that the distribution of cohorts and covariates is stable across dates. Here population parallel trends hold and the cohort shares are stable, but the first condition fails for cohort 3. Its observed units come mostly from $\alpha = +1$ at early dates and mostly from $\alpha = -1$ at late dates, so each level contrast adds a change in composition to the effect.&lt;/p>
&lt;p>Fixed differences between units do not cause this on their own. The never treated units take the same two values of $\alpha$, but their windows do not depend on it, so their observed levels represent their cohort at every date. If the windows of cohort 3 were also drawn independently of $\alpha$, as in the rotating example of &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/">Estimate treatment effects from incomplete panels&lt;/a>, the observed levels would represent both cohorts, and the RCS approach would target the same effects under its assumptions. Ordinary unbalanced mode uses RCS routines; whether it answers the question depends on its sampling conditions.&lt;/p>
&lt;h2 id="assumptions-in-this-example">Assumptions in this example&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Item&lt;/th>
&lt;th>In this example&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Whose effect&lt;/td>
&lt;td>ATT(3,t) for t = 3, 4, 5 in the original study population&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Comparison group&lt;/td>
&lt;td>Units never treated, G=0&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Anticipation&lt;/td>
&lt;td>None, so the reference period of cohort 3 is date 2&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Parallel trends&lt;/td>
&lt;td>PT-post from date 2, true in the design&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Observed changes&lt;/td>
&lt;td>&lt;code>selection(none)&lt;/code>: within each cohort, units observed at both dates of a pair have the cohort&amp;rsquo;s mean change; true because observation depends only on the cohort and $\alpha$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Treatment adjustment&lt;/td>
&lt;td>Treatment weighting by inverse probability weighting (IPW) with an intercept only, no covariates; adequate because parallel trends hold without covariates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Overlap and support&lt;/td>
&lt;td>Every window has positive probability in both cohorts; in a sample, a window with no observed unit makes the effects that depend on it unavailable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Unit table&lt;/td>
&lt;td>One row per unit with &lt;code>id&lt;/code> and &lt;code>g&lt;/code>; no covariates or weights&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="stata-usage">Stata usage&lt;/h2>
&lt;p>The tables on this page give population values, not estimates. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/#comparing-modechained-and-modeordinary-in-stata">Incomplete panels&lt;/a> applies the three estimation approaches to the data of the hands-on do-file, which follow a different design; their estimates are not the values in these tables. Representative mean changes are conditions on population expectations, not equal sample means, equal levels, equal fixed components or equal distributions.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 4 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/">Estimate treatment effects from incomplete panels&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/precision/">How to compare precision&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Impute actual changes for missing outcomes</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/change-imputation/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/change-imputation/</guid><description>&lt;p>Under &lt;code>selection(conditional_mtar)&lt;/code>, observation weighting (&lt;code>selmethod(ipw)&lt;/code>) reweights the changes of units observed at both endpoints of a date pair. Change imputation (&lt;code>selmethod(imputation)&lt;/code>) instead predicts the actual outcome change of every unit in the cohort from its covariates, and the augmented doubly robust correction (&lt;code>selmethod(dr)&lt;/code>) combines prediction with inverse observation-probability weighting (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>).&lt;/p>
&lt;p>This page distinguishes the imputation of actual changes from the regression of counterfactual changes and illustrates the pooling choices. Sections 5a and 5b of the hands-on do-file apply pure imputation and the augmented correction.&lt;/p>
&lt;h2 id="1-two-outcome-regressions-j-versus-m">1. Two outcome regressions: $j$ versus $m$&lt;/h2>
&lt;p>Change imputation fits a linear model $j$ of &lt;strong>actual cohort changes&lt;/strong>. It is distinct from the counterfactual control regression $m$ of &lt;code>method(reg)&lt;/code> and &lt;code>method(dr)&lt;/code>:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Feature&lt;/th>
&lt;th>Actual-change model $j_c(X)$&lt;/th>
&lt;th>Counterfactual control regression $m_b(X)$&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Layer &amp;amp; option&lt;/td>
&lt;td>Handling missing outcomes: &lt;code>selmethod(imputation)&lt;/code> or &lt;code>selmethod(dr)&lt;/code>&lt;/td>
&lt;td>Treatment adjustment: &lt;code>method(reg)&lt;/code> or &lt;code>method(dr)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Predicts&lt;/td>
&lt;td>The &lt;strong>actual&lt;/strong> change $\Delta_e Y = Y_t - Y_s$ of cohort $k$ over pair $e$, &lt;strong>treatment effects included&lt;/strong>&lt;/td>
&lt;td>The &lt;strong>untreated&lt;/strong> change $\Delta_e Y(0)$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Fitted to&lt;/td>
&lt;td>Units of cohort $k$ observed at both endpoints of pair $e$ ($S_{i,e} = 1$)&lt;/td>
&lt;td>Reconstructed control changes on deduplicated comparison blocks $b = (e, K)$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Slopes&lt;/td>
&lt;td>Shared according to &lt;code>imppooling(separate|within_cohort|across_cohorts)&lt;/code>&lt;/td>
&lt;td>Controlled by &lt;code>outcomepooling(separate|pooled)&lt;/code> (default &lt;code>separate&lt;/code> per block $b$; &lt;code>pooled&lt;/code> shares one $\beta$ across blocks)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Both $j$ and $m$ read the treatment covariate list (&lt;code>indepvars&lt;/code> or &lt;code>covars(varlist)&lt;/code>, and &lt;code>framecovars(varlist)&lt;/code>). By contrast, &lt;code>selcovars(varlist)&lt;/code> and &lt;code>frameselcovars(varlist)&lt;/code> define only the observation-probability logit $q$.&lt;/p>
&lt;h2 id="2-how-change-imputation-works-selmethodimputation">2. How change imputation works (&lt;code>selmethod(imputation)&lt;/code>)&lt;/h2>
&lt;p>For each needed cohort $k$ and ordered date pair $e = (s, t)$, &lt;code>cdid&lt;/code> fits $j_{k,e}(X_i)$ by weighted least squares to the units of cohort $k$ observed at both $s$ and $t$ ($S_{i,e} = 1$):&lt;/p>
&lt;p>$$j_{k,e}(X_i) = \alpha_{k,e} + L(e), z(X_i)'\beta_r$$&lt;/p>
&lt;p>where $L(e) = i_t - i_s$ counts calendar steps in the stored calendar, $\alpha_{k,e}$ is a local cell intercept (unless &lt;code>noconstant&lt;/code> is specified), and $\beta_r$ is the slope vector of imputation pooling group $r$.&lt;/p>
&lt;p>The fitted model $\hat{j}_{k,e}(X_i)$ is then evaluated for &lt;strong>every unit of cohort $k$ in the study population $F$&lt;/strong> (&lt;code>frame()&lt;/code>), including units whose change was observed, singletons observed once ($B \setminus A$), and unit-table-only units observed never ($F \setminus B$). The average of these predictions over $F$ replaces the observed cohort mean:&lt;/p>
&lt;ul>
&lt;li>You do not fill in &lt;code>y&lt;/code> in your dataset; &lt;code>y&lt;/code> remains &lt;code>.&lt;/code> where missing.&lt;/li>
&lt;li>A singleton unit observed at only one date supplies no training pair ($S_{i,e} = 0$), and the method does not condition on its single observed outcome level to impute the missing endpoint; it evaluates the predicted change $\hat{j}_{k,e}(X_i)$ from $X_i$.&lt;/li>
&lt;li>Under pure imputation (&lt;code>selmethod(imputation)&lt;/code>), &lt;code>selmodel()&lt;/code>, &lt;code>selpooling()&lt;/code>, and &lt;code>selcovars()&lt;/code> do not apply (&lt;code>e(inactive_options)&lt;/code> lists them, together with &lt;code>outcomepooling()&lt;/code> under &lt;code>method(ipw)&lt;/code>), and no observation logit $q$ is fitted.&lt;/li>
&lt;/ul>
&lt;h2 id="3-three-kinds-of-slope-sharing-imppooling">3. Three kinds of slope sharing (&lt;code>imppooling()&lt;/code>)&lt;/h2>
&lt;p>Because $j_{k,e}(X_i)$ predicts &lt;strong>actual&lt;/strong> changes, including treatment effects for treated cohorts when $t \ge g$, it must represent how treatment effects vary with $X_i$:&lt;/p>
&lt;ul>
&lt;li>Suppose untreated outcome changes have slope $\beta_0, L(e)$ on $X_i$, while treatment adds an extra effect $\delta_X, X_i$ at post-treatment dates $t \ge g$.&lt;/li>
&lt;li>For any pair $e = (s, t)$ of treated cohort $g$ that &lt;strong>crosses treatment onset&lt;/strong> ($s &amp;lt; g \le t$), the actual change $\Delta_e Y_i$ has total slope $\beta_0, L(e) + \delta_X$ on $X_i$, so the duration-scaled slope $\beta_r$ in $L(e), X_i'\beta_r$ equals $\beta_0 + \delta_X / L(e)$.&lt;/li>
&lt;li>For pre-treatment pairs ($s &amp;lt; t &amp;lt; g$), post-onset pairs where the effect on $X_i$ is constant after onset ($g \le s &amp;lt; t$), and control cohort pairs ($k = 0$), the duration-scaled slope is $\beta_0$.&lt;/li>
&lt;/ul>
&lt;p>This makes the three &lt;code>imppooling()&lt;/code> options distinct restrictions:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;code>imppooling()&lt;/code>&lt;/th>
&lt;th>Slopes of $j$&lt;/th>
&lt;th>Implication when treatment effects vary with $X_i$ ($\delta_X \ne 0$)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>separate&lt;/code> (default)&lt;/td>
&lt;td>Separate slope vector $\beta_{k,e}$ for each cohort and pair $(k, e)$&lt;/td>
&lt;td>Correctly accommodates pair-specific slope shifts $\beta_0 + \delta_X / L(e)$ on treatment-crossing pairs.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>within_cohort&lt;/code>&lt;/td>
&lt;td>One shared slope vector $\beta_k$ per cohort across all of its pairs&lt;/td>
&lt;td>Forces pre-treatment pairs, treatment-crossing pairs, and post-treatment pairs of cohort $g$ to share one duration-scaled slope $\beta_g$, which is misspecified when $\delta_X \ne 0$.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>across_cohorts&lt;/code>&lt;/td>
&lt;td>One global slope vector $\beta$ across all cohorts and pairs&lt;/td>
&lt;td>Forces treated and control cohorts to share one duration-scaled slope $\beta$, which is misspecified when $\delta_X \ne 0$.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Each cohort and pair keeps its local intercept $\alpha_{k,e}$ whenever &lt;code>noconstant&lt;/code> is not specified.&lt;/p>
&lt;h2 id="4-the-augmented-doubly-robust-correction-selmethoddr">4. The augmented doubly robust correction (&lt;code>selmethod(dr)&lt;/code>)&lt;/h2>
&lt;p>When &lt;code>selmethod(dr)&lt;/code> is specified alongside built-in &lt;code>method(ipw|reg|dr)&lt;/code> on &lt;code>seluniverse(F)&lt;/code> (with &lt;code>selrho()&lt;/code> omitted), &lt;code>cdid&lt;/code> fits &lt;strong>both&lt;/strong> $j_c(X_i)$ and $q_c(W_i)$ and reconstructs for every unit $i$ of cohort $k$ in $F$:&lt;/p>
&lt;p>$$Z_{i,c} = \hat{j}&lt;em>c(X_i) + S&lt;/em>{i,e},\frac{\Delta_{i,e} - \hat{j}_c(X_i)}{\max(\hat{q}_c(W_i),, 10^{-6})}$$&lt;/p>
&lt;p>and then runs the chosen built-in treatment adjustment (&lt;code>method(ipw)&lt;/code>, &lt;code>method(reg)&lt;/code>, or &lt;code>method(dr)&lt;/code>) on $Z_{i,c}$.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Correction&lt;/th>
&lt;th>Missing-outcome layer requirement&lt;/th>
&lt;th>Treatment layer requirement (&lt;code>method(ipw|reg|dr)&lt;/code>)&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>selmethod(ipw)&lt;/code>&lt;/td>
&lt;td>$q_c$ correct in every needed cell&lt;/td>
&lt;td>&lt;code>ipw&lt;/code>: $p$ correct; &lt;code>reg&lt;/code>: $m$ correct; &lt;code>dr&lt;/code>: $p$ &lt;strong>or&lt;/strong> $m$ correct&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(imputation)&lt;/code>&lt;/td>
&lt;td>$j_c$ correct in every needed cell/pooling group&lt;/td>
&lt;td>&lt;code>ipw&lt;/code>: $p$ correct; &lt;code>reg&lt;/code>: $m$ correct; &lt;code>dr&lt;/code>: $p$ &lt;strong>or&lt;/strong> $m$ correct&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(dr)&lt;/code>&lt;/td>
&lt;td>For each needed cell $c$, $q_c$ correct &lt;strong>or&lt;/strong> $j_c$ correct&lt;/td>
&lt;td>&lt;code>ipw&lt;/code>: $p$ correct; &lt;code>reg&lt;/code>: $m$ correct; &lt;code>dr&lt;/code>: $p$ &lt;strong>or&lt;/strong> $m$ correct&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Note that under pure imputation (&lt;code>selmethod(imputation)&lt;/code>), &lt;code>method(dr)&lt;/code> does &lt;strong>not&lt;/strong> repair a misspecified imputer $j_c$: if $j_c$ is misspecified, the reconstructed cohort changes fed into treatment adjustment are already biased unless repaired by the observation-weighted residual term in &lt;code>selmethod(dr)&lt;/code> (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/">Compare model robustness&lt;/a>).&lt;/p>
&lt;h2 id="5-examples-in-stata">5. Examples in Stata&lt;/h2>
&lt;p>Section 5 of the hands-on do-file runs pure imputation and the augmented correction, with separate pooling:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) selection(conditional_mtar) ///
selmethod(imputation) imppooling(separate) ///
biters($CDID_DEMO_BITERS)
display as text &amp;quot;Inactive options under selmethod(imputation): &amp;quot; as result &amp;quot;`e(inactive_options)'&amp;quot;
* 5b. Doubly robust observation + treatment adjustment (`selmethod(dr)` with `method(dr)`)
cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) selection(conditional_mtar) ///
selmethod(dr) selmodel(pair_logit) selpooling(separate) ///
selcovars(i.x_bin c.x_cont c.z_sel) imppooling(separate) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;p>To compare other imputation restrictions, change &lt;code>imppooling(separate)&lt;/code> to &lt;code>within_cohort&lt;/code> or &lt;code>across_cohorts&lt;/code> while holding the remaining specification and target fixed. The restrictions can be false when covariates modify treatment effects. A small SE or a successful fit does not establish their validity.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 12 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/observation-models/">Choose an observation model for missing outcomes&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/">Parallel trends&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Installing cdid</title><link>https://www.davidbenatia.com/tools/cdid/stata/installation/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/installation/</guid><description>&lt;p>These pages describe &lt;code>cdid&lt;/code> 1.0.0.0 for Stata.&lt;/p>
&lt;h2 id="requirements">Requirements&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> requires Stata 19.5 (StataNow) or later. It has been tested with StataNow 19.5 on macOS (Apple silicon). The estimation commands are written in Stata and Mata; no other software is needed.&lt;/p>
&lt;p>Chained mode, the default, has no other dependency. Ordinary mode (&lt;code>mode(ordinary)&lt;/code>, or &lt;code>rcs&lt;/code>) uses the &lt;code>csdid&lt;/code> package, version 2.0.2, by Brantly Callaway, Fernando Rios-Avila and Pedro H. C. Sant&amp;rsquo;Anna. It is distributed with &lt;code>cdid&lt;/code> under its MIT license but is installed separately, so that an existing installation of &lt;code>csdid&lt;/code> is never replaced without your consent.&lt;/p>
&lt;h2 id="install-from-github">Install from GitHub&lt;/h2>
&lt;pre>&lt;code class="language-stata">net install cdid, from(&amp;quot;https://raw.githubusercontent.com/dvbn/cdid-stata/main&amp;quot;)
mata: mata mlib index
&lt;/code>&lt;/pre>
&lt;p>To use ordinary mode, also install &lt;code>csdid&lt;/code> 2.0.2:&lt;/p>
&lt;pre>&lt;code class="language-stata">net install csdid, from(&amp;quot;https://raw.githubusercontent.com/dvbn/cdid-stata/main/csdid&amp;quot;)
mata: mata mlib index
csdid version
&lt;/code>&lt;/pre>
&lt;p>If &lt;code>csdid&lt;/code> is already installed, check its version with &lt;code>csdid version&lt;/code> and its location with &lt;code>which csdid, all&lt;/code> before installing. Ordinary mode stops with an error if the version found is not 2.0.2. To keep another version for other projects, install &lt;code>cdid&lt;/code> and &lt;code>csdid&lt;/code> 2.0.2 into a project folder as described below.&lt;/p>
&lt;h2 id="install-into-a-project-folder">Install into a project folder&lt;/h2>
&lt;p>The following commands, typed in a new Stata session started in the project folder, install both packages into subfolders of the project. They change the search path of the current session only; no profile file is modified. See &lt;code>help sysdir&lt;/code> and &lt;code>help net&lt;/code>.&lt;/p>
&lt;pre>&lt;code class="language-stata">mkdir &amp;quot;./ado_plus&amp;quot;
mkdir &amp;quot;./ado_personal&amp;quot;
sysdir set PLUS &amp;quot;./ado_plus&amp;quot;
sysdir set PERSONAL &amp;quot;./ado_personal&amp;quot;
net install cdid, from(&amp;quot;https://raw.githubusercontent.com/dvbn/cdid-stata/main&amp;quot;)
net install csdid, from(&amp;quot;https://raw.githubusercontent.com/dvbn/cdid-stata/main/csdid&amp;quot;)
mata: mata mlib index
&lt;/code>&lt;/pre>
&lt;p>Repeat the &lt;code>sysdir set&lt;/code> commands at the start of each session that uses this installation. To install from a local copy of the repository, replace the URLs with the path of that copy, for example &lt;code>net install cdid, from(&amp;quot;/path/to/cdid-stata&amp;quot;)&lt;/code>.&lt;/p>
&lt;h2 id="example-files">Example files&lt;/h2>
&lt;p>The example do-files and the documentation are ancillary files. To copy them into the current working folder, type&lt;/p>
&lt;pre>&lt;code class="language-stata">net get cdid, from(&amp;quot;https://raw.githubusercontent.com/dvbn/cdid-stata/main&amp;quot;)
&lt;/code>&lt;/pre>
&lt;p>This copies &lt;code>cdid_hands_on.do&lt;/code> and &lt;code>cdid_custom_estimators.do&lt;/code>, among other files; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/hands-on/">Hands-on guide&lt;/a> and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/custom-estimators/">Custom estimators&lt;/a>. &lt;code>cdid_hands_on.do&lt;/code> begins with a block of settings that you can edit before running it; it clears the data in memory only if you allow it to, and it keeps output files when you give it an output folder.&lt;/p>
&lt;h2 id="check-the-installation">Check the installation&lt;/h2>
&lt;pre>&lt;code class="language-stata">which cdid
which cdid_pretest
which cdid_diagnostics
which cdid_plot
which cdid_export
which cdid_load
which cdid_pretest_load
which cdid_nuisance
which cdid_chain
findfile lcdid_native.mlib
&lt;/code>&lt;/pre>
&lt;p>Each command should be found in the folder where you installed &lt;code>cdid&lt;/code>.&lt;/p>
&lt;h2 id="building-the-mata-library">Building the Mata library&lt;/h2>
&lt;p>The installed library &lt;code>lcdid_native.mlib&lt;/code> is compiled from the Mata source files in the repository&amp;rsquo;s &lt;code>mata/&lt;/code> folder. To rebuild it from a copy of the repository, start Stata in the repository folder and type&lt;/p>
&lt;pre>&lt;code class="language-stata">mkdir &amp;quot;./build_lib&amp;quot;
do tools/build_native.do &amp;quot;.&amp;quot; &amp;quot;.&amp;quot; &amp;quot;./build_lib&amp;quot;
&lt;/code>&lt;/pre>
&lt;p>The new library is written to &lt;code>build_lib/lcdid_native.mlib&lt;/code>. Building is never required to use &lt;code>cdid&lt;/code>.&lt;/p></description></item><item><title>Investigate missingness and data structure</title><link>https://www.davidbenatia.com/tools/cdid/stata/help/investigate-missingness/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/help/investigate-missingness/</guid><description>&lt;p>Before choosing an assumption about missing outcomes or a model to adjust for them, inspect how many outcomes each unit has, the coverage of each cohort and date, the overlap of pairs of dates, and the composition of the covariates. No diagnostic proves that mean changes are representative or that the covariates are sufficient.&lt;/p>
&lt;h2 id="1-count-observed-outcomes-not-rows">1. Count observed outcomes, not rows&lt;/h2>
&lt;p>The examples use the data of the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/hands-on/">hands-on do-file&lt;/a>; run its Sections 0 and 1 first. These data have a row for every unit and date, including missing outcomes. Counting &lt;code>_N&lt;/code> per unit would therefore count every unit as fully observed. Section 2 of the do-file counts nonmissing &lt;code>y&lt;/code>:&lt;/p>
&lt;pre>&lt;code class="language-stata">* 2a. Count observed outcome dates per unit across all units in the long dataset
tempvar n_obs_unit tag_unit
bysort id: egen long `n_obs_unit' = count(y)
bysort id: generate byte `tag_unit' = (_n == 1)
display as text _n &amp;quot;=== Unit-level count of observed outcome dates (0, 1, &amp;gt;=2) ===&amp;quot;
tabulate `n_obs_unit' first_treat if `tag_unit', missing
* 2b. Inspect outcome observation rates by calendar period and cohort
display as text _n &amp;quot;=== Outcome observation indicator (obs_y) by period and cohort ===&amp;quot;
tabulate period first_treat, summarize(obs_y) means
* 2c. Compare covariate composition across all units vs repeat-observer units (&amp;gt;=2 dates)
display as text _n &amp;quot;=== Covariate means: all population units vs units with &amp;gt;=2 observed dates ===&amp;quot;
summarize x_bin x_cont z_sel if `tag_unit'
summarize x_bin x_cont z_sel if `tag_unit' &amp;amp; `n_obs_unit' &amp;gt;= 2
&lt;/code>&lt;/pre>
&lt;p>These counts distinguish the study population $F$, units observed at least once ($B$), units observed at least twice ($A$), singletons $B\setminus A$, and never-observed units $F\setminus B$. If units with no observed outcome have no rows in the long data, merge the counts with the unit table and set their count to zero. Do not count omitted or missing outcomes as observed dates.&lt;/p>
&lt;h2 id="2-observation-models-and-support">2. Observation models and support&lt;/h2>
&lt;p>An observation logit with a free intercept has no finite estimate in a cell where every unit, or no unit, is observed. Pooling the slopes keeps the cell intercepts and does not solve this. Pure imputation has no observation logit, but has its own requirements: enough observed changes, full rank, and support for prediction. A complete cell alone therefore does not guarantee a successful imputation analysis.&lt;/p>
&lt;p>Independent-period logits also require that observation at the two dates be independent given the cohort and the covariates. Rotating windows and persistent dropout generally violate this product-probability assumption. Pair logits model the joint indicator directly, but still need a correct covariate specification.&lt;/p>
&lt;h2 id="3-inspect-the-results">3. Inspect the results&lt;/h2>
&lt;p>After a fit, run &lt;code>cdid_diagnostics&lt;/code>:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) bstrap(0) cband(0)
cdid_diagnostics, detail
display &amp;quot;units: &amp;quot; r(N_units) &amp;quot;, at least one outcome: &amp;quot; r(N_with_outcome) &amp;quot;, at least two: &amp;quot; r(N_with_two_outcomes)
&lt;/code>&lt;/pre>
&lt;p>The diagnostics report the population counts, the reasons for unavailable cells, the models and GMM settings, and the inference. A quantity that was not stored with the results is reported as not retained, not as zero. Available unit covariates and observation counts can motivate substantive investigation, but neither logit significance nor a good response-model fit establishes the outcome mean-change assumption or valid transport. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Missing outcomes&lt;/a> and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/sampling-information/">Sampling information&lt;/a>.&lt;/p>
&lt;hr>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Moving from did and csdid</title><link>https://www.davidbenatia.com/tools/cdid/stata/from-did/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/from-did/</guid><description>&lt;p>&lt;code>cdid&lt;/code> keeps the workflow of Callaway and Sant&amp;rsquo;Anna (2021), implemented in R by &lt;code>did&lt;/code> and in Stata by &lt;code>csdid&lt;/code>, and extends it to incomplete panels with the chained difference-in-differences estimator of Bellégo, Benatia and Dortet-Bernadet (2025). Users of R &lt;code>cdid&lt;/code> will find the argument-by-argument mapping in &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-r-cdid/">Moving from R cdid&lt;/a>.&lt;/p>
&lt;h2 id="what-stays-the-same">What stays the same&lt;/h2>
&lt;p>Cohorts $g$, dates $t$ and group-time effects $\text{ATT}(g,t)$ have the same meaning. The treatment adjustments (&lt;code>dr&lt;/code>, &lt;code>reg&lt;/code>, &lt;code>ipw&lt;/code>), the control groups (&lt;code>nevertreated&lt;/code>, &lt;code>notyettreated&lt;/code>), the base periods (&lt;code>varying&lt;/code>, &lt;code>universal&lt;/code>), anticipation, multiplier-bootstrap bands and the four aggregations work as in &lt;code>did&lt;/code>. The defaults are those of &lt;code>did&lt;/code>: doubly robust adjustment, never-treated controls, no anticipation, a varying base period and 1000 bootstrap draws with simultaneous bands.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Concept&lt;/th>
&lt;th>Stata &lt;code>csdid&lt;/code> 2.0.2&lt;/th>
&lt;th>Stata &lt;code>cdid&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Group-time estimation&lt;/td>
&lt;td>&lt;code>csdid y x, ivar(id) time(t) gvar(g)&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid y x, ivar(id) time(t) gvar(g)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Estimator family&lt;/td>
&lt;td>Ordinary DiD&lt;/td>
&lt;td>&lt;code>mode(chained)&lt;/code> (default) or &lt;code>mode(ordinary)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Repeated cross sections&lt;/td>
&lt;td>omit &lt;code>ivar()&lt;/code>&lt;/td>
&lt;td>&lt;code>rcs&lt;/code> (implies ordinary mode)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Treatment adjustment&lt;/td>
&lt;td>&lt;code>method(dr)&lt;/code> (default), &lt;code>method(reg)&lt;/code>, &lt;code>method(ipw)&lt;/code>&lt;/td>
&lt;td>&lt;code>method(dr)&lt;/code> (default), &lt;code>method(reg)&lt;/code>, &lt;code>method(ipw)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Comparison group&lt;/td>
&lt;td>not-yet-treated (default); &lt;code>nevertreated&lt;/code>&lt;/td>
&lt;td>never-treated (default); &lt;code>controlgroup(notyettreated)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Base period&lt;/td>
&lt;td>universal (default); &lt;code>base_period(varying)&lt;/code>&lt;/td>
&lt;td>varying (default); &lt;code>baseperiod(universal)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Aggregations&lt;/td>
&lt;td>&lt;code>estat simple|group|event|calendar&lt;/code>&lt;/td>
&lt;td>&lt;code>estat simple|group|dynamic|calendar&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Plot&lt;/td>
&lt;td>&lt;code>csdid_plot&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_plot&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Binary treatment with entry and exit&lt;/td>
&lt;td>not available&lt;/td>
&lt;td>&lt;code>dvar()&lt;/code>; see &lt;code>help cdid_dvar&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="two-estimation-modes">Two estimation modes&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Chained mode&lt;/strong>, the default with panel data, uses the outcome changes of each unit between the dates at which it is observed and combines them by GMM.&lt;/li>
&lt;li>&lt;strong>Ordinary mode&lt;/strong>, requested with &lt;code>mode(ordinary)&lt;/code> or &lt;code>rcs&lt;/code>, computes the estimators of Callaway and Sant&amp;rsquo;Anna (2021) with &lt;code>csdid&lt;/code> 2.0.2, installed separately (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/installation/">Installation&lt;/a>). &lt;code>cdid&lt;/code> prepares the sample, sets the options of &lt;code>csdid&lt;/code>, and stores the results in the same form as in chained mode, so &lt;code>estat&lt;/code>, &lt;code>cdid_plot&lt;/code>, &lt;code>cdid_export&lt;/code>, &lt;code>cdid_load&lt;/code> and &lt;code>cdid_diagnostics&lt;/code> work in both modes.&lt;/li>
&lt;/ul>
&lt;p>Ordinary estimation with panel data requires a numeric &lt;code>ivar()&lt;/code>. With &lt;code>rcs&lt;/code>, it may be omitted. Ordinary estimation takes covariates from the varlist and refuses &lt;code>covars()&lt;/code>, &lt;code>noconstant&lt;/code>, &lt;code>panel()&lt;/code>, &lt;code>frame()&lt;/code> and its associated options. Chained-mode options such as &lt;code>selection()&lt;/code>, the &lt;code>sel*()&lt;/code> options and the GMM options have no effect on an ordinary fit. &lt;code>e(inactive_options)&lt;/code> lists all accepted inactive options, and the note names those supplied in the command.&lt;/p>
&lt;h2 id="incomplete-panels-in-ordinary-and-chained-mode">Incomplete panels in ordinary and chained mode&lt;/h2>
&lt;p>By default, ordinary mode keeps only the units observed at every date, as &lt;code>did&lt;/code> does with a balanced panel, and a note reports how many units were dropped. With &lt;code>allowunbalanced&lt;/code>, ordinary mode keeps all units and estimates each effect with the repeated cross-section estimators, which compare outcome levels; standard errors are clustered by &lt;code>ivar()&lt;/code>. Those comparisons are valid when the observed units at each date represent the population at that date.&lt;/p>
&lt;p>Chained mode uses every unit observed at least twice and keeps units observed once or never in the study population. It requires the units observed at both dates of a comparison to represent their cohort&amp;rsquo;s mean change, possibly after a correction for missing outcomes (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>). Fixed unit components cancel from these changes. In &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/get-started/#compare-with-ordinary-did">Get started&lt;/a>, ordinary mode keeps 98 of 600 units of a panel with one outcome in five missing, while chained mode uses all of them.&lt;/p>
&lt;h2 id="when-chained-and-ordinary-estimates-should-agree">When chained and ordinary estimates should agree&lt;/h2>
&lt;p>In a balanced panel, chained and ordinary point estimates agree up to rounding with built-in IPW, no covariates, no missing-outcome correction, never-treated controls, PT-post, weights that are constant over time, and the same anticipation and reporting settings: the cohort means then telescope. This equality does not extend in general to OR and DR, standard errors, bands or aggregations.&lt;/p>
&lt;h2 id="why-balanced-results-can-differ">Why balanced results can differ&lt;/h2>
&lt;p>Chained OR and DR regress the controls' outcome changes on covariates, one regression per comparison by default (&lt;code>outcomepooling(separate)&lt;/code>) or with slopes shared across comparisons (&lt;code>outcomepooling(pooled)&lt;/code>). Even with separate regressions, chained estimation combines multi-step and direct comparisons by GMM, so identical variable lists do not imply identical fitted systems.&lt;/p>
&lt;p>With not-yet-treated controls, chained estimation can also use the same pair of dates again at a later horizon with a different control group. For ATT(3,3) with reference date 2 and cohorts 0, 3 and 5, ordinary estimation uses cohort 3 against &lt;code>{0,5}&lt;/code> on the pair (2,3). Chained estimation also uses that pair against &lt;code>{0}&lt;/code> at a later horizon, after cohort 5 is treated. Both comparisons require not-yet-treated parallel trends and overlap at their dates; a claim only about the combined &lt;code>{0,5}&lt;/code> pool at date 3 does not justify the &lt;code>{0}&lt;/code> reuse. The additional comparisons can change finite-sample estimates; they do not by themselves make the estimates more precise.&lt;/p>
&lt;p>Which to use: with a complete panel and no reason to expect selective observation, both are valid under their assumptions, and agreement in the settings listed above is a useful check. With missing outcomes, chained mode is the safer choice unless observation can be taken to be unrelated to persistent differences between units, provided its own assumptions about the changes hold.&lt;/p>
&lt;h2 id="what-chained-mode-adds">What chained mode adds&lt;/h2>
&lt;ul>
&lt;li>&lt;code>frame()&lt;/code> supplies the study population, so that units observed once or never still count in the cohort shares, covariate distributions and influence functions (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/">Prepare your panel&lt;/a>).&lt;/li>
&lt;li>&lt;code>selection(conditional_mtar)&lt;/code> separates the assumption about missing outcomes from the treatment adjustment, with observation weighting, change imputation or the augmented correction (&lt;code>selmethod()&lt;/code>).&lt;/li>
&lt;li>&lt;code>ptassumption(all)&lt;/code> and &lt;code>ptassumption(ctrl)&lt;/code> add parallel trends restrictions before the reference period, independently of how &lt;code>baseperiod()&lt;/code> reports pretreatment cells (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/">Parallel trends&lt;/a>).&lt;/li>
&lt;li>&lt;code>crosspair&lt;/code>, &lt;code>gmmweighting(within)&lt;/code> and &lt;code>cdid_chain&lt;/code> link cohorts observed over different windows and show which comparisons identify each effect (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining&lt;/a>).&lt;/li>
&lt;li>&lt;code>preset(cohort_time_fe)&lt;/code> fits the linear cohort-by-date fixed-effects specification (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cohort-time-fe/">Cohort-by-date fixed effects&lt;/a>).&lt;/li>
&lt;li>&lt;code>cdid_pretest&lt;/code> runs the conditional pretrend test of Callaway and Sant&amp;rsquo;Anna (2021), with IPW by default; it leaves the current &lt;code>e()&lt;/code> results unchanged.&lt;/li>
&lt;li>&lt;code>missingreference()&lt;/code> sets what happens when a covariate that varies over time is missing at a cohort&amp;rsquo;s reference date.&lt;/li>
&lt;/ul>
&lt;h2 id="ordinary-mode-details">Ordinary-mode details&lt;/h2>
&lt;ul>
&lt;li>The doubly robust estimator for repeated cross sections, also used for unbalanced panels in ordinary mode, uses the influence function of &lt;code>DRDID&lt;/code> 1.4.0, which corrected the sign of a pre-period term of earlier versions. Point estimates do not depend on this correction; standard errors do.&lt;/li>
&lt;li>The ordinary conditional pretrend test follows &lt;code>did&lt;/code> 2.5.1, including its defaults when the model has no covariates or the data have no unit identifier; see &lt;code>help cdid_pretest&lt;/code>.&lt;/li>
&lt;/ul>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 2 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/get-started/">Get started: estimate effects in an incomplete panel&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/incomplete-panels/">Estimate treatment effects from incomplete panels&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Moving from R cdid</title><link>https://www.davidbenatia.com/tools/cdid/stata/from-r-cdid/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/from-r-cdid/</guid><description>&lt;p>&lt;code>cdid&lt;/code> for Stata follows the estimators and defaults of &lt;a href="https://github.com/dvbn/cdid/tree/v1.3.0.0" target="_blank" rel="noopener">R &lt;code>cdid&lt;/code> 1.3.0.0&lt;/a>. The &lt;a href="#differences-to-keep-in-mind">differences below&lt;/a> describe the behavior of each interface. This page maps R functions and arguments to Stata commands and options. &amp;ldquo;Corresponds&amp;rdquo; means the same estimator with the same defaults. Estimates and standard errors were compared with R on the configurations of the Stata test suite and agree there up to numerical precision; agreement is not established beyond them, and multiplier-bootstrap draws come from Stata&amp;rsquo;s random-number generator and differ from R&amp;rsquo;s.&lt;/p>
&lt;h2 id="functions">Functions&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>R &lt;code>cdid&lt;/code>&lt;/th>
&lt;th>Stata &lt;code>cdid&lt;/code>&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>att_gt(gname = ...)&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid depvar [indepvars], ivar() time() gvar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>att_gt(dname = ...)&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid depvar [indepvars], ivar() time() dvar()&lt;/code>; see &lt;code>help cdid_dvar&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>summary(fit)&lt;/code>, &lt;code>print(fit)&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid&lt;/code> (replay)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>aggte(fit, type = &amp;quot;simple&amp;quot;|&amp;quot;group&amp;quot;|&amp;quot;dynamic&amp;quot;|&amp;quot;calendar&amp;quot;)&lt;/code>&lt;/td>
&lt;td>&lt;code>estat simple|group|dynamic|calendar&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ggdid()&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_plot&lt;/code> (&lt;code>twoway&lt;/code> options in place of the &lt;code>ggplot&lt;/code> arguments)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>tidy()&lt;/code>, &lt;code>glance()&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_export, type(cells)&lt;/code> or &lt;code>type(aggregate)&lt;/code>, &lt;code>type(summary)&lt;/code>, and &lt;code>e()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>conditional_did_pretest()&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_pretest&lt;/code> (results in &lt;code>r()&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>chain_report(fit, cohort, time, include_pre, tol)&lt;/code> (&lt;code>group&lt;/code> and &lt;code>t&lt;/code> are aliases of &lt;code>cohort&lt;/code> and &lt;code>time&lt;/code>); its print method with &lt;code>show_gmm_weights = TRUE&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_chain, cohort() time() pre tol()&lt;/code>; &lt;code>weights&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>as.data.frame(report, what = &amp;quot;summary&amp;quot;|&amp;quot;witness&amp;quot;|&amp;quot;gmm_weights&amp;quot;)&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_chain, saving() table(summary|witness|weights)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>nuisance_models(fit, component, block)&lt;/code>&lt;/td>
&lt;td>&lt;code>cdid_nuisance component, block()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>saveRDS()&lt;/code>, &lt;code>readRDS()&lt;/code>&lt;/td>
&lt;td>&lt;code>saving()&lt;/code>, &lt;code>cdid_load&lt;/code>, &lt;code>cdid_pretest_load&lt;/code>, for &lt;code>gvar()&lt;/code> fits, their aggregations and pretests; &lt;code>dvar()&lt;/code> results cannot be saved&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>fit$aggregate&lt;/code> (switching model)&lt;/td>
&lt;td>&lt;code>e(att)&lt;/code>, &lt;code>e(se_att)&lt;/code> after &lt;code>dvar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="arguments-of-att_gt-with-gname">Arguments of att_gt() with gname&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>R argument&lt;/th>
&lt;th>Stata option&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>yname&lt;/code>&lt;/td>
&lt;td>&lt;code>depvar&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>tname&lt;/code>&lt;/td>
&lt;td>&lt;code>time()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>idname&lt;/code>&lt;/td>
&lt;td>&lt;code>ivar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gname&lt;/code>&lt;/td>
&lt;td>&lt;code>gvar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>xformla&lt;/code>&lt;/td>
&lt;td>&lt;code>indepvars&lt;/code> or &lt;code>covars()&lt;/code>; &lt;code>~ -1 + ...&lt;/code> is &lt;code>noconstant&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>data&lt;/code>&lt;/td>
&lt;td>the data in memory&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>panel = FALSE&lt;/code>&lt;/td>
&lt;td>&lt;code>rcs&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>allow_unbalanced_panel&lt;/code>&lt;/td>
&lt;td>&lt;code>allowunbalanced&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control_group&lt;/code>&lt;/td>
&lt;td>&lt;code>controlgroup()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>anticipation&lt;/code>&lt;/td>
&lt;td>&lt;code>anticipation()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>weightsname&lt;/code>&lt;/td>
&lt;td>&lt;code>[iweight = ...]&lt;/code> or &lt;code>wvar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>fix_weights&lt;/code>&lt;/td>
&lt;td>&lt;code>fixweights()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>alp&lt;/code>&lt;/td>
&lt;td>&lt;code>level()&lt;/code>, with &lt;code>alp = 1 - level/100&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>na.rm&lt;/code> (in &lt;code>aggte()&lt;/code>)&lt;/td>
&lt;td>&lt;code>narm&lt;/code> of &lt;code>estat&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>bstrap&lt;/code>, &lt;code>cband&lt;/code>, &lt;code>biters&lt;/code>&lt;/td>
&lt;td>&lt;code>bstrap()&lt;/code>, &lt;code>cband()&lt;/code>, &lt;code>biters()&lt;/code> (0 or 1 for the first two)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>clustervars&lt;/code>&lt;/td>
&lt;td>&lt;code>cluster()&lt;/code> (one variable besides the unit identifier)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>est_method&lt;/code>&lt;/td>
&lt;td>&lt;code>method()&lt;/code>; an R function corresponds to &lt;code>method(custom) callback()&lt;/code>, a Mata function, and the arguments passed through &lt;code>...&lt;/code> to &lt;code>payload()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>base_period&lt;/code>&lt;/td>
&lt;td>&lt;code>baseperiod()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>compute_inffunc = FALSE&lt;/code>&lt;/td>
&lt;td>&lt;code>noinffunc&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>mode&lt;/code>&lt;/td>
&lt;td>&lt;code>mode()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>pt_assumption&lt;/code>, &lt;code>pt_start&lt;/code>&lt;/td>
&lt;td>&lt;code>ptassumption()&lt;/code>, &lt;code>ptstart()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gmm_weighting&lt;/code>, &lt;code>gmm_covariance&lt;/code>&lt;/td>
&lt;td>&lt;code>gmmweighting()&lt;/code>, &lt;code>gmmcovariance()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cross_pair = TRUE&lt;/code>&lt;/td>
&lt;td>&lt;code>crosspair&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>outcome_pooling&lt;/code>&lt;/td>
&lt;td>&lt;code>outcomepooling()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>frame&lt;/code>&lt;/td>
&lt;td>&lt;code>frame()&lt;/code>, with &lt;code>frameivar()&lt;/code>, &lt;code>framegvar()&lt;/code>, &lt;code>framecovars()&lt;/code>, &lt;code>framewvar()&lt;/code>, &lt;code>frameselcovars()&lt;/code>, &lt;code>framecluster()&lt;/code> naming its columns&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection&lt;/code>&lt;/td>
&lt;td>&lt;code>selection()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_est_method&lt;/code>&lt;/td>
&lt;td>&lt;code>selmethod()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_model&lt;/code>&lt;/td>
&lt;td>&lt;code>selmodel()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_pooling&lt;/code>&lt;/td>
&lt;td>&lt;code>selpooling()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_xformla&lt;/code>&lt;/td>
&lt;td>&lt;code>selcovars()&lt;/code>; &lt;code>~ 1&lt;/code> is &lt;code>selconstant&lt;/code>, &lt;code>~ -1 + ...&lt;/code> is &lt;code>selnoconstant&lt;/code>, &lt;code>~ 0&lt;/code> is &lt;code>selzero&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_universe&lt;/code>&lt;/td>
&lt;td>&lt;code>seluniverse()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_rho&lt;/code>&lt;/td>
&lt;td>&lt;code>selrho()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_justification&lt;/code>&lt;/td>
&lt;td>&lt;code>seljustification()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>imputation_pooling&lt;/code>&lt;/td>
&lt;td>&lt;code>imppooling()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>missing_reference&lt;/code>&lt;/td>
&lt;td>&lt;code>missingreference()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$preset&lt;/code>&lt;/td>
&lt;td>&lt;code>preset()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$keep_nuisance&lt;/code>&lt;/td>
&lt;td>&lt;code>keepnuisance&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$numeric_workspace_bytes&lt;/code>&lt;/td>
&lt;td>&lt;code>workspace()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$chunk_rows&lt;/code>&lt;/td>
&lt;td>&lt;code>chunk()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$counted_work_limit&lt;/code>&lt;/td>
&lt;td>&lt;code>workcap()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$condition_trigger&lt;/code>&lt;/td>
&lt;td>&lt;code>condition()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>control$ridge_relative&lt;/code>&lt;/td>
&lt;td>&lt;code>ridge()&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Values are spelled as in R (&lt;code>&amp;quot;nevertreated&amp;quot;&lt;/code> is &lt;code>nevertreated&lt;/code>), and a Stata option that is omitted takes the R default.&lt;/p>
&lt;h2 id="arguments-of-att_gt-with-dname">Arguments of att_gt() with dname&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>R argument&lt;/th>
&lt;th>Stata option&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>dname&lt;/code>&lt;/td>
&lt;td>&lt;code>dvar()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>switchers&lt;/code>, &lt;code>switch_times&lt;/code>&lt;/td>
&lt;td>&lt;code>switchers()&lt;/code>, &lt;code>switchtimes()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>outcome_pooling&lt;/code>&lt;/td>
&lt;td>&lt;code>outcomepooling()&lt;/code>, including blocks of cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>imputation_scale&lt;/code>&lt;/td>
&lt;td>&lt;code>impscale()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection_pooling&lt;/code>, &lt;code>imputation_pooling&lt;/code>&lt;/td>
&lt;td>&lt;code>selpooling()&lt;/code>, &lt;code>imppooling()&lt;/code> (&lt;code>separate&lt;/code>, &lt;code>within_group&lt;/code>, &lt;code>pooled&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>other arguments&lt;/td>
&lt;td>as with &lt;code>gname&lt;/code>, where accepted; see &lt;code>help cdid_dvar&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="arguments-of-aggte-and-conditional_did_pretest">Arguments of aggte() and conditional_did_pretest()&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>R argument&lt;/th>
&lt;th>Stata option&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>type&lt;/code>&lt;/td>
&lt;td>the &lt;code>estat&lt;/code> subcommand&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>min_e&lt;/code>, &lt;code>max_e&lt;/code>, &lt;code>balance_e&lt;/code>&lt;/td>
&lt;td>&lt;code>mine()&lt;/code>, &lt;code>maxe()&lt;/code>, &lt;code>balancee()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>na.rm&lt;/code>&lt;/td>
&lt;td>&lt;code>narm&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>bstrap&lt;/code>, &lt;code>cband&lt;/code>, &lt;code>biters&lt;/code>, &lt;code>alp&lt;/code>, &lt;code>clustervars&lt;/code>&lt;/td>
&lt;td>&lt;code>bstrap()&lt;/code>, &lt;code>cband()&lt;/code>, &lt;code>biters()&lt;/code>, &lt;code>level()&lt;/code>, &lt;code>cluster()&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>pl&lt;/code>, &lt;code>cores&lt;/code> (pretest)&lt;/td>
&lt;td>&lt;code>pl()&lt;/code>, &lt;code>cores()&lt;/code>; only &lt;code>pl(0) cores(1)&lt;/code> is accepted, and the Stata test runs serially&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="r-arguments-without-a-stata-option">R arguments without a Stata option&lt;/h2>
&lt;p>None of these arguments changes the estimator.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>R function&lt;/th>
&lt;th>Argument&lt;/th>
&lt;th>Reason&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>att_gt()&lt;/code>&lt;/td>
&lt;td>&lt;code>faster_mode&lt;/code>&lt;/td>
&lt;td>Selects the computational path of &lt;code>did&lt;/code> in ordinary mode; Stata&amp;rsquo;s ordinary mode is computed by &lt;code>csdid&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>att_gt()&lt;/code>, &lt;code>conditional_did_pretest()&lt;/code>&lt;/td>
&lt;td>&lt;code>print_details&lt;/code>&lt;/td>
&lt;td>Progress printing.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>att_gt()&lt;/code>, &lt;code>conditional_did_pretest()&lt;/code>&lt;/td>
&lt;td>&lt;code>pl&lt;/code>, &lt;code>cores&lt;/code>&lt;/td>
&lt;td>Parallel bootstrap. &lt;code>cdid&lt;/code> has neither option; &lt;code>cdid_pretest&lt;/code> accepts only &lt;code>pl(0) cores(1)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>att_gt()&lt;/code>, &lt;code>conditional_did_pretest()&lt;/code>&lt;/td>
&lt;td>&lt;code>control$workers&lt;/code>&lt;/td>
&lt;td>Number of parallel workers in chained mode.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>print method of &lt;code>chain_report()&lt;/code>&lt;/td>
&lt;td>&lt;code>digits&lt;/code>, &lt;code>max_cells&lt;/code>&lt;/td>
&lt;td>Printing.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ggdid()&lt;/code>&lt;/td>
&lt;td>&lt;code>ylim&lt;/code>, &lt;code>xlab&lt;/code>, &lt;code>ylab&lt;/code>, &lt;code>title&lt;/code>, &lt;code>xgap&lt;/code>, &lt;code>ncol&lt;/code>, &lt;code>legend&lt;/code>, &lt;code>ref_line&lt;/code>, &lt;code>theme_choice&lt;/code>, &amp;hellip;&lt;/td>
&lt;td>Graphics; &lt;code>cdid_plot&lt;/code> accepts &lt;code>twoway&lt;/code> options instead.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>tidy()&lt;/code>, &lt;code>glance()&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>Summaries; &lt;code>cdid_export&lt;/code> writes the tables.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="stata-options-without-an-r-argument">Stata options without an R argument&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Command&lt;/th>
&lt;th>Option&lt;/th>
&lt;th>Purpose&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>cdid&lt;/code>&lt;/td>
&lt;td>&lt;code>targets()&lt;/code>, &lt;code>targetcohorts()&lt;/code>&lt;/td>
&lt;td>Restrict the target cohorts; R estimates all of them.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid&lt;/code>, &lt;code>estat&lt;/code>, &lt;code>cdid_pretest&lt;/code>, &lt;code>cdid_load&lt;/code>, &lt;code>cdid_pretest_load&lt;/code>&lt;/td>
&lt;td>&lt;code>posting(matrix|state)&lt;/code>, &lt;code>store()&lt;/code>&lt;/td>
&lt;td>How results are posted in Stata, given its matrix size limit.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid&lt;/code>, &lt;code>estat&lt;/code>, &lt;code>cdid_pretest&lt;/code>&lt;/td>
&lt;td>&lt;code>saving()&lt;/code>&lt;/td>
&lt;td>Save the results to a file; R uses &lt;code>saveRDS()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_pretest&lt;/code>&lt;/td>
&lt;td>&lt;code>signs()&lt;/code>&lt;/td>
&lt;td>Supply the bootstrap multipliers.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>estat&lt;/code>, &lt;code>cdid_load&lt;/code>, &lt;code>cdid_pretest_load&lt;/code>&lt;/td>
&lt;td>&lt;code>workspace()&lt;/code>, &lt;code>chunk()&lt;/code> (&lt;code>estat&lt;/code> only)&lt;/td>
&lt;td>Memory limits; R reuses the settings of the fit.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_chain&lt;/code>&lt;/td>
&lt;td>&lt;code>saving()&lt;/code>, &lt;code>table()&lt;/code>&lt;/td>
&lt;td>Save a chain table; R uses &lt;code>as.data.frame()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_plot&lt;/code>&lt;/td>
&lt;td>&lt;code>group()&lt;/code>, &lt;code>cells&lt;/code>, &lt;code>saving()&lt;/code>, &lt;code>export()&lt;/code>, &lt;code>plotdata()&lt;/code>, &lt;code>replace&lt;/code>&lt;/td>
&lt;td>Graph control.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_export&lt;/code>&lt;/td>
&lt;td>&lt;code>type()&lt;/code>, &lt;code>replace&lt;/code>&lt;/td>
&lt;td>Tables as Stata datasets.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_diagnostics&lt;/code>&lt;/td>
&lt;td>&lt;code>detail&lt;/code>&lt;/td>
&lt;td>Lists unavailable cells; in R, inspect the result object.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="differences-to-keep-in-mind">Differences to keep in mind&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Ordinary mode.&lt;/strong> R &lt;code>cdid&lt;/code> delegates ordinary mode to &lt;code>did&lt;/code> (version 2.5.1 in the comparisons). Stata &lt;code>cdid&lt;/code> uses &lt;code>csdid&lt;/code> 2.0.2, installed separately. The ordinary fit lists all accepted inactive options in &lt;code>e(inactive_options)&lt;/code>, including &lt;code>selection()&lt;/code>, the &lt;code>sel*()&lt;/code> options and &lt;code>keepnuisance&lt;/code>. Ordinary &lt;code>cdid&lt;/code> refuses &lt;code>covars()&lt;/code>, &lt;code>noconstant&lt;/code>, &lt;code>panel()&lt;/code>, &lt;code>frame()&lt;/code> and its associated options. Ordinary &lt;code>cdid_pretest&lt;/code> uses &lt;code>covars()&lt;/code>, &lt;code>noconstant&lt;/code> and &lt;code>panel()&lt;/code>, and treats &lt;code>frame()&lt;/code> and its associated options as inactive. Its &lt;code>r(inactive_options)&lt;/code> lists all accepted inactive options. Each command displays a note naming those supplied.&lt;/li>
&lt;li>&lt;strong>Clustering of aggregations.&lt;/strong> &lt;code>estat&lt;/code> inherits the clustering of the fit. After an ordinary fit, &lt;code>cluster(none)&lt;/code> or the &lt;code>ivar()&lt;/code> variable requests unit-level inference. A request for an unavailable cluster variable warns and uses unit-level inference for both analytical and bootstrap standard errors, as in R&amp;rsquo;s ordinary &lt;code>aggte()&lt;/code>. After a chained fit, a request to change clustering stops with an error.&lt;/li>
&lt;li>&lt;strong>Printed output.&lt;/strong> &lt;code>cdid_pretest&lt;/code> displays the test, as R&amp;rsquo;s print method; its results are in &lt;code>r()&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Results.&lt;/strong> Stata results are posted in &lt;code>e()&lt;/code> and &lt;code>r()&lt;/code> rather than in a fitted object; &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/">Results&lt;/a> lists them, and &lt;code>cdid_export&lt;/code> writes the tables that &lt;code>tidy()&lt;/code> returns in R.&lt;/li>
&lt;li>&lt;strong>Factor covariates.&lt;/strong> Factor-variable notation (&lt;code>i.&lt;/code>, &lt;code>ib#.&lt;/code>, &lt;code>#&lt;/code>, &lt;code>##&lt;/code>) corresponds to R&amp;rsquo;s &lt;code>factor()&lt;/code> treatment contrasts with the same base. A factor interacted with a continuous covariate without the main effect, &lt;code>i.cf#c.x&lt;/code> or &lt;code>ibn.cf#c.x&lt;/code>, keeps one slope per level, as R&amp;rsquo;s &lt;code>factor(cf):x&lt;/code>; with the main effect of the continuous covariate, &lt;code>c.x i.cf#c.x&lt;/code> drops the base level, as R&amp;rsquo;s &lt;code>x + factor(cf):x&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Comparisons with other software.&lt;/strong> &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/">Estimate familiar DiD models with cdid&lt;/a> compares with Stata commands where the R guide compares with R packages, and reports a numerical match only where both sides were run in Stata.&lt;/li>
&lt;/ul></description></item><item><title>Options reference</title><link>https://www.davidbenatia.com/tools/cdid/stata/reference/options/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/reference/options/</guid><description>&lt;p>This page lists every option of every command with its default, its accepted values and the estimators that accept it. The help files (&lt;code>help cdid&lt;/code>, &lt;code>help cdid_dvar&lt;/code>, &lt;code>help cdid postestimation&lt;/code> and the help file of each command) give the same information in Stata&amp;rsquo;s format, and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-r-cdid/">Moving from R cdid&lt;/a> gives the R argument of each option.&lt;/p>
&lt;p>In the column &lt;strong>Estimators&lt;/strong>, &lt;em>chained&lt;/em> is chained cohort estimation with &lt;code>gvar()&lt;/code> (the default), &lt;em>cross-pair&lt;/em> is chained estimation with &lt;code>crosspair&lt;/code>, &lt;em>preset&lt;/em> is &lt;code>preset(cohort_time_fe)&lt;/code>, and &lt;em>ordinary&lt;/em> is &lt;code>mode(ordinary)&lt;/code> or &lt;code>rcs&lt;/code>. Options of &lt;code>dvar()&lt;/code> estimation have their own section.&lt;/p>
&lt;h2 id="signatures">Signatures&lt;/h2>
&lt;pre>&lt;code class="language-text">cdid depvar [indepvars] [if] [in] [iweight], time(varname) gvar(varname) [ivar(varname) options]
cdid depvar [indepvars] [if] [in], ivar(varname) time(varname) dvar(varname) [dvar_options]
cdid
estat {simple|group|dynamic|calendar} [, estat_options]
cdid_pretest depvar [indepvars] [if] [in] [iweight], time(varname) gvar(varname) [ivar(varname) options]
cdid_chain [, cohort(numlist) time(numlist) pre weights tol(#) saving(filename[, replace]) table(name)]
cdid_nuisance [selection|outcome|treatment|imputation] [, block(id)]
cdid_diagnostics [, detail]
cdid_plot [, group(numlist) cells saving(filename[, replace]) export(filename[, replace options]) plotdata(filename[, replace]) replace twoway_options]
cdid_export using filename [, type(cells|aggregate|units|influence|summary) replace]
cdid_load using filename [, posting(matrix|state) workspace(#)]
cdid_pretest_load using filename [, store(name) posting(matrix|state) workspace(#)]
&lt;/code>&lt;/pre>
&lt;p>Minimal abbreviations: &lt;code>nocons(tant)&lt;/code>, &lt;code>control(group)&lt;/code>, &lt;code>anticip(ation)&lt;/code>, &lt;code>base(period)&lt;/code>, &lt;code>l(evel)&lt;/code>, &lt;code>cross(pair)&lt;/code>, &lt;code>missingref(erence)&lt;/code>, &lt;code>selnocons(tant)&lt;/code>, &lt;code>selcons(tant)&lt;/code>.&lt;/p>
&lt;h2 id="data-timing-and-comparison-group">Data, timing and comparison group&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>depvar&lt;/code>&lt;/td>
&lt;td>required&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Numeric outcome; missing values are unobserved outcomes.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>time(varname)&lt;/code>&lt;/td>
&lt;td>required&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Numeric study date.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gvar(varname)&lt;/code>&lt;/td>
&lt;td>required&lt;/td>
&lt;td>all&lt;/td>
&lt;td>First treatment date, constant within unit, nonnegative and nonmissing; 0 for never-treated units.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ivar(varname)&lt;/code>&lt;/td>
&lt;td>required in chained mode&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Unit identifier, numeric or string; numeric in ordinary mode; may be omitted with &lt;code>rcs&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>controlgroup(nevertreated|notyettreated)&lt;/code>&lt;/td>
&lt;td>&lt;code>nevertreated&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Never-treated units, or never-treated units together with units not yet treated at the dates compared.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>anticipation(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>0&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Periods of anticipation; the reference date of cohort $g$ is the latest study date $d$ with $d + # &amp;lt; g$. The preset requires 0.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>targetcohorts(numlist)&lt;/code>&lt;/td>
&lt;td>all treated cohorts&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Target cohorts; not with &lt;code>targets()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>targets(matname)&lt;/code>&lt;/td>
&lt;td>all treated cohorts&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Target cohorts as a one-column matrix; not with &lt;code>targetcohorts()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>By default, every treated cohort whose treatment date is on or before the last study date is a target; the effects of a cohort g with no study date d such that d + anticipation &amp;lt; g are reported as unavailable.&lt;/p>
&lt;h2 id="treatment-adjustment">Treatment adjustment&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>indepvars&lt;/code>, &lt;code>covars(varlist)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>all; &lt;code>covars()&lt;/code> not in ordinary mode&lt;/td>
&lt;td>Covariates of the treatment, outcome and imputation models; one or the other. Factor variables allowed.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>noconstant&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Omit the intercept from the treatment and outcome designs.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>method(dr|ipw|reg|custom)&lt;/code>&lt;/td>
&lt;td>&lt;code>dr&lt;/code>&lt;/td>
&lt;td>all; preset: &lt;code>reg&lt;/code>, &lt;code>ipw&lt;/code>, &lt;code>dr&lt;/code>&lt;/td>
&lt;td>Doubly robust, inverse probability weighting, outcome regression, or a Mata function.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>outcomepooling(separate|pooled)&lt;/code>&lt;/td>
&lt;td>&lt;code>separate&lt;/code>&lt;/td>
&lt;td>chained, cross-pair; preset: &lt;code>separate&lt;/code> only&lt;/td>
&lt;td>One regression of the controls' changes per comparison, or slopes shared across comparisons with local intercepts; applies to &lt;code>reg&lt;/code> and &lt;code>dr&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>callback(name)&lt;/code>, &lt;code>payload(name)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, ordinary&lt;/td>
&lt;td>Mata function and object for &lt;code>method(custom)&lt;/code>; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/custom-estimators/">Custom estimators&lt;/a>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="covariates-that-vary-over-time">Covariates that vary over time&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>missingreference(exclude|error)&lt;/code>&lt;/td>
&lt;td>&lt;code>exclude&lt;/code>&lt;/td>
&lt;td>chained, cross-pair; ignored in ordinary mode; &lt;code>exclude&lt;/code> refused with the preset&lt;/td>
&lt;td>When a covariate that varies over time is missing at the date where a cohort&amp;rsquo;s comparisons read it: exclude the unit from that cohort&amp;rsquo;s comparisons with a warning, or stop with error 459 and list the missing values. Identical results when nothing is missing. Weights are not covered: with &lt;code>fixweights()&lt;/code>, every unit used needs a positive weight at its anchor date.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>fixweights(first_period|base_period)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair; ordinary also &lt;code>varying&lt;/code>&lt;/td>
&lt;td>Weight at the first study date or at each target cohort&amp;rsquo;s reference date when weights vary within units. Without it, weights must be constant within units.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Covariates that vary over time are read at the reference date of each target cohort for its post-treatment comparisons and at the earlier date of each pretrend comparison; with &lt;code>crosspair&lt;/code>, every comparison of cohort $g$ reads them at $g$&amp;rsquo;s reference date. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/#reference-dates-for-covariates-that-change-within-a-unit">Prepare your panel&lt;/a>.&lt;/p>
&lt;h2 id="handling-missing-outcomes">Handling missing outcomes&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>selection(none|conditional_mtar)&lt;/code>&lt;/td>
&lt;td>&lt;code>none&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Assumption about missing outcomes; &lt;code>corollary1&lt;/code> is a synonym of &lt;code>conditional_mtar&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(ipw|imputation|dr)&lt;/code>&lt;/td>
&lt;td>&lt;code>ipw&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Observation weighting, change imputation or the augmented correction. &lt;code>method(custom)&lt;/code> supports &lt;code>ipw&lt;/code> only.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmodel(pair_logit|independent_period_logit)&lt;/code>&lt;/td>
&lt;td>&lt;code>pair_logit&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Logit for observing both dates of a pair, or product of logits for each date.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selpooling(separate|within_cohort|across_cohorts)&lt;/code>&lt;/td>
&lt;td>&lt;code>separate&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Slopes of the observation logits.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>imppooling(separate|within_cohort|across_cohorts)&lt;/code>&lt;/td>
&lt;td>&lt;code>separate&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Slopes of the imputation regressions.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selcovars(varlist)&lt;/code>&lt;/td>
&lt;td>the outcome covariates&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Observation-model covariates; factor variables allowed.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selnoconstant&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>No intercept in the observation logits.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selconstant&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Intercept-only observation logits; not with &lt;code>selcovars()&lt;/code>, &lt;code>frameselcovars()&lt;/code>, &lt;code>selnoconstant&lt;/code> or &lt;code>selzero&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selzero&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>No observation design.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>seluniverse(F|B|A)&lt;/code>&lt;/td>
&lt;td>&lt;code>F&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Units that fit the observation model: study population, units with at least one, or at least two, observed outcomes. &lt;code>B&lt;/code> and &lt;code>A&lt;/code> require &lt;code>selmethod(ipw)&lt;/code>, &lt;code>selmodel(pair_logit)&lt;/code> and &lt;code>seljustification()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selrho(varname)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Known density ratio with &lt;code>B&lt;/code> or &lt;code>A&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>seljustification(string)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Stated justification; required with &lt;code>B&lt;/code> or &lt;code>A&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a> and &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/sampling-information/">Sampling information&lt;/a>.&lt;/p>
&lt;h2 id="parallel-trends-and-reporting">Parallel trends and reporting&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>ptassumption(post|ctrl|all)&lt;/code>&lt;/td>
&lt;td>&lt;code>post&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>PT from each reference date onward; &lt;code>ctrl&lt;/code> adds common trends among eligible control cohorts from &lt;code>ptstart()&lt;/code>, which is optional and defaults to the first study date; &lt;code>all&lt;/code> adds common trends of target and controls from &lt;code>ptstart()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ptstart(#)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>A study date; required with &lt;code>all&lt;/code>, optional with &lt;code>ctrl&lt;/code>, not allowed with &lt;code>post&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>baseperiod(varying|universal)&lt;/code>&lt;/td>
&lt;td>&lt;code>varying&lt;/code>&lt;/td>
&lt;td>all; preset: &lt;code>universal&lt;/code>&lt;/td>
&lt;td>Reporting of pretreatment cells: relative to the preceding date, or to the reference date.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="chaining-and-designs">Chaining and designs&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>crosspair&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>chained&lt;/td>
&lt;td>Separate within-unit changes of target and control cohorts linked by GMM; not in ordinary mode, with &lt;code>method(custom)&lt;/code> or with the preset. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>preset(cohort_time_fe)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained&lt;/td>
&lt;td>Linear cohort-by-date fixed effects; requires chained mode without &lt;code>crosspair&lt;/code>, unit weights, &lt;code>anticipation(0)&lt;/code>, &lt;code>baseperiod(universal)&lt;/code>, &lt;code>ptassumption(post)&lt;/code> with never-treated controls or &lt;code>ptassumption(all) ptstart(first date)&lt;/code> with not-yet-treated controls, and positive consecutive integer dates. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cohort-time-fe/">Cohort-by-date fixed effects&lt;/a>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>keepnuisance&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Keep reports of the fitted models for &lt;code>cdid_nuisance&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="gmm-weighting-and-covariance-regularization">GMM weighting and covariance regularization&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>gmmweighting(optimal|two_step|within|identity)&lt;/code>&lt;/td>
&lt;td>&lt;code>optimal&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>&lt;code>two_step&lt;/code> is a synonym of &lt;code>optimal&lt;/code>. &lt;code>within&lt;/code> is not available with &lt;code>method(custom)&lt;/code>. With the preset, &lt;code>method(reg)&lt;/code> allows only &lt;code>within&lt;/code>, and &lt;code>method(ipw)&lt;/code> or &lt;code>method(dr)&lt;/code> allow &lt;code>optimal&lt;/code>, &lt;code>two_step&lt;/code> or &lt;code>identity&lt;/code>, not &lt;code>within&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gmmcovariance(tikhonov)&lt;/code>&lt;/td>
&lt;td>&lt;code>tikhonov&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Only value.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>condition(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1e-10&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Relative eigenvalue threshold in (0, 1) that triggers regularization.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ridge(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1e-4&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Relative Tikhonov multiplier, &amp;gt; 0.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/">GMM weighting&lt;/a>.&lt;/p>
&lt;h2 id="study-population-and-weights">Study population and weights&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>frame(name)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Frame with one row per study unit.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>frameivar(name)&lt;/code>&lt;/td>
&lt;td>the &lt;code>ivar()&lt;/code> name&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Unit identifier in the frame.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>framegvar(name)&lt;/code>, &lt;code>framecovars(varlist)&lt;/code>, &lt;code>frameselcovars(varlist)&lt;/code>, &lt;code>framewvar(name)&lt;/code>, &lt;code>framecluster(name)&lt;/code>&lt;/td>
&lt;td>not read&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Frame columns; read only when named; require &lt;code>frame()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>iweight&lt;/code>, &lt;code>wvar(varname)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair, ordinary&lt;/td>
&lt;td>Positive sampling weights; one or the other; refused with the preset.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="inference">Inference&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>bstrap(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>1: multiplier bootstrap; 0: analytical standard errors.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cband(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>1: simultaneous bands; 0: pointwise intervals.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>biters(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1000&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Bootstrap draws, at least 1.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>level(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>95&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Confidence level.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cluster(varname)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>all&lt;/td>
&lt;td>One cluster variable, constant within units.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>noinffunc&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Point estimates only; &lt;code>estat&lt;/code> is then refused.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="mode">Mode&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>mode(chained|ordinary)&lt;/code>&lt;/td>
&lt;td>&lt;code>chained&lt;/code> with panel data&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Estimator family. Ordinary mode uses &lt;code>csdid&lt;/code> 2.0.2.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>rcs&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>ordinary&lt;/td>
&lt;td>Repeated cross sections; implies ordinary mode; refused with &lt;code>mode(chained)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>panel(true|1)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Accepted; redundant. Refused in ordinary mode.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>allowunbalanced&lt;/code>, &lt;code>allowunbalanced(true|false)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>In ordinary mode, keep units not observed at every date (repeated cross-section estimators). In chained mode only &lt;code>true&lt;/code> is accepted, and it changes nothing.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Ordinary estimation takes covariates from the varlist and refuses &lt;code>covars()&lt;/code>, &lt;code>noconstant&lt;/code>, &lt;code>panel()&lt;/code>, &lt;code>frame()&lt;/code> and its associated options. &lt;code>e(inactive_options)&lt;/code> lists every accepted option that has no effect in ordinary mode: &lt;code>ptassumption()&lt;/code>, &lt;code>ptstart()&lt;/code>, &lt;code>targets()&lt;/code>, &lt;code>targetcohorts()&lt;/code>, &lt;code>gmmweighting()&lt;/code>, &lt;code>gmmcovariance()&lt;/code>, &lt;code>workcap()&lt;/code>, &lt;code>condition()&lt;/code>, &lt;code>ridge()&lt;/code>, &lt;code>selection()&lt;/code>, the &lt;code>sel*()&lt;/code> options, &lt;code>outcomepooling()&lt;/code>, &lt;code>imppooling()&lt;/code>, &lt;code>missingreference()&lt;/code> and &lt;code>keepnuisance&lt;/code>. The note names those supplied in the command. &lt;code>ivar()&lt;/code> is required for panel data and may be omitted with &lt;code>rcs&lt;/code>.&lt;/p>
&lt;h2 id="computation-and-reporting">Computation and reporting&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Estimators&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>workspace(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1073741824&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Memory limit for the main numerical arrays, in bytes.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>chunk(#)&lt;/code>&lt;/td>
&lt;td>automatic; &lt;code>1024&lt;/code> in ordinary mode&lt;/td>
&lt;td>chained, cross-pair, preset, ordinary&lt;/td>
&lt;td>Rows per processing block.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>workcap(#)&lt;/code>&lt;/td>
&lt;td>unlimited&lt;/td>
&lt;td>chained, cross-pair, preset&lt;/td>
&lt;td>Limit on counted operations.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>posting(matrix|state)&lt;/code>&lt;/td>
&lt;td>&lt;code>matrix&lt;/code>&lt;/td>
&lt;td>chained, cross-pair, preset, ordinary&lt;/td>
&lt;td>Post &lt;code>e(b)&lt;/code> and &lt;code>e(V)&lt;/code>, or keep the results without posting them.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>saving(filename)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>chained, cross-pair, preset, ordinary&lt;/td>
&lt;td>Save the complete results for &lt;code>cdid_load&lt;/code>; never overwrites.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="options-with-dvar">Options with dvar()&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>dvar(varname)&lt;/code>&lt;/td>
&lt;td>required&lt;/td>
&lt;td>Treatment status, 0 or 1, no missing values.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>ivar()&lt;/code>, &lt;code>time()&lt;/code>&lt;/td>
&lt;td>required&lt;/td>
&lt;td>Unit identifier and date.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>indepvars&lt;/code>, &lt;code>covars(varlist)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Covariates, read at $t-1$; factor variables allowed.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>method(dr|ipw|reg)&lt;/code>&lt;/td>
&lt;td>&lt;code>dr&lt;/code>&lt;/td>
&lt;td>Treatment adjustment.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>switchers(both|entry|exit)&lt;/code>&lt;/td>
&lt;td>&lt;code>both&lt;/code>&lt;/td>
&lt;td>Directions of the requested cells.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>switchtimes(numlist)&lt;/code>&lt;/td>
&lt;td>dates with switchers&lt;/td>
&lt;td>Dates of the requested cells.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>outcomepooling(separate|pooled|&lt;/code>&lt;em>blocks&lt;/em>&lt;code>)&lt;/code>&lt;/td>
&lt;td>&lt;code>separate&lt;/code>&lt;/td>
&lt;td>One stayer regression per cell, common slopes, or blocks such as &lt;code>entry:2003 entry:2004 | exit:2003 exit:2004&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gmmweighting(optimal|two_step|identity)&lt;/code>&lt;/td>
&lt;td>&lt;code>optimal&lt;/code>&lt;/td>
&lt;td>With chained comparisons under missing outcomes.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gmmcovariance(tikhonov)&lt;/code>, &lt;code>condition(#)&lt;/code>, &lt;code>ridge(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>tikhonov&lt;/code>, &lt;code>1e-10&lt;/code>, &lt;code>1e-4&lt;/code>&lt;/td>
&lt;td>As for &lt;code>gvar()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selection(none|conditional_mtar)&lt;/code>&lt;/td>
&lt;td>&lt;code>none&lt;/code>&lt;/td>
&lt;td>Assumption about missing outcomes.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmethod(ipw|imputation|dr)&lt;/code>&lt;/td>
&lt;td>&lt;code>ipw&lt;/code>&lt;/td>
&lt;td>&lt;code>imputation&lt;/code> and &lt;code>dr&lt;/code> require &lt;code>conditional_mtar&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selmodel(pair_logit|independent_period_logit)&lt;/code>&lt;/td>
&lt;td>&lt;code>pair_logit&lt;/code>&lt;/td>
&lt;td>Observation model.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selpooling()&lt;/code>, &lt;code>imppooling()&lt;/code>&lt;/td>
&lt;td>&lt;code>separate&lt;/code>&lt;/td>
&lt;td>&lt;code>separate&lt;/code>, &lt;code>within_group&lt;/code> or &lt;code>pooled&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>impscale(per_period|per_change)&lt;/code>&lt;/td>
&lt;td>&lt;code>per_period&lt;/code>&lt;/td>
&lt;td>Scaling of the imputation covariates by the length of a pair.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selcovars(varlist)&lt;/code>, &lt;code>selconstant&lt;/code>&lt;/td>
&lt;td>outcome covariates&lt;/td>
&lt;td>Not both.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>seluniverse(F|B|A)&lt;/code>&lt;/td>
&lt;td>&lt;code>F&lt;/code>&lt;/td>
&lt;td>&lt;code>B&lt;/code> and &lt;code>A&lt;/code> require &lt;code>conditional_mtar&lt;/code>, &lt;code>ipw&lt;/code>, &lt;code>pair_logit&lt;/code> and &lt;code>seljustification()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>selrho(varname)&lt;/code>, &lt;code>seljustification(string)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>With &lt;code>B&lt;/code> or &lt;code>A&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cluster(varname)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>At least two clusters.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>noinffunc&lt;/code>, &lt;code>bstrap()&lt;/code>, &lt;code>cband()&lt;/code>, &lt;code>biters()&lt;/code>, &lt;code>level()&lt;/code>, &lt;code>workspace()&lt;/code>&lt;/td>
&lt;td>as for &lt;code>gvar()&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>keepnuisance&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>Keep reports for &lt;code>cdid_nuisance&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>mode(chained)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>Accepted; the only mode.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>missingreference(error)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>Accepted; &lt;code>exclude&lt;/code> is refused.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Weights, &lt;code>gvar()&lt;/code> and every other option, including &lt;code>saving()&lt;/code>, &lt;code>crosspair&lt;/code>, &lt;code>controlgroup()&lt;/code>, &lt;code>ptassumption()&lt;/code>, &lt;code>anticipation()&lt;/code>, &lt;code>method(custom)&lt;/code> and &lt;code>gmmweighting(within)&lt;/code>, are refused with error 198.&lt;/p>
&lt;h2 id="estat-options">estat options&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>mine(#)&lt;/code>, &lt;code>maxe(#)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>&lt;code>estat dynamic&lt;/code>: bounds of the event time t - g, in date units. &lt;code>maxe()&lt;/code> also limits &lt;code>estat simple&lt;/code> and &lt;code>estat group&lt;/code> to post-treatment cells whose horizon, counted in positions of the sorted dates, is at most #.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>balancee(#)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>&lt;code>estat dynamic&lt;/code>: keep the cohorts observed for at least # periods after treatment.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>narm&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>Aggregate the available cells when some are unavailable.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>bstrap(#)&lt;/code>, &lt;code>cband(#)&lt;/code>, &lt;code>biters(#)&lt;/code>, &lt;code>level(#)&lt;/code>&lt;/td>
&lt;td>those of the fit&lt;/td>
&lt;td>Inference of the aggregation.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cluster(varname)&lt;/code>&lt;/td>
&lt;td>that of the fit&lt;/td>
&lt;td>After an ordinary fit, &lt;code>cluster(none)&lt;/code> or the &lt;code>ivar()&lt;/code> variable requests unit-level inference. A request for an unavailable cluster variable warns and uses unit-level inference. After a chained fit, a request to change clustering stops with an error.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>workspace(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1073741824&lt;/code>&lt;/td>
&lt;td>Memory limit in bytes.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>chunk(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1024&lt;/code>&lt;/td>
&lt;td>Rows per processing block.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>posting(matrix|state)&lt;/code>&lt;/td>
&lt;td>&lt;code>matrix&lt;/code>&lt;/td>
&lt;td>As for &lt;code>cdid&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>saving(filename)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Save the aggregation for &lt;code>cdid_load&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>mine()&lt;/code> and &lt;code>balancee()&lt;/code> have no effect on &lt;code>estat simple&lt;/code> and &lt;code>estat group&lt;/code>; &lt;code>estat calendar&lt;/code> ignores all three, with a note. &lt;code>estat&lt;/code> is not available after &lt;code>dvar()&lt;/code> estimation or after &lt;code>noinffunc&lt;/code>.&lt;/p>
&lt;h2 id="cdid_pretest-options">cdid_pretest options&lt;/h2>
&lt;p>&lt;code>cdid_pretest&lt;/code> accepts the model, mode, missing-outcome, study-population and weight options of &lt;code>cdid&lt;/code> (&lt;code>ivar()&lt;/code>, &lt;code>covars()&lt;/code>, &lt;code>noconstant&lt;/code>, &lt;code>mode()&lt;/code>, &lt;code>rcs&lt;/code>, &lt;code>controlgroup()&lt;/code>, &lt;code>anticipation()&lt;/code>, &lt;code>baseperiod()&lt;/code>, &lt;code>outcomepooling()&lt;/code>, &lt;code>callback()&lt;/code>, &lt;code>payload()&lt;/code>, &lt;code>wvar()&lt;/code>, &lt;code>fixweights()&lt;/code>, &lt;code>frame()&lt;/code>, &lt;code>frameivar()&lt;/code>, &lt;code>framegvar()&lt;/code>, &lt;code>framecovars()&lt;/code>, &lt;code>framewvar()&lt;/code>, &lt;code>framecluster()&lt;/code>, &lt;code>frameselcovars()&lt;/code>, the &lt;code>sel*()&lt;/code> options, &lt;code>imppooling()&lt;/code>, &lt;code>cluster()&lt;/code>, &lt;code>workspace()&lt;/code>, &lt;code>chunk()&lt;/code>, &lt;code>workcap()&lt;/code>), with these differences:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>method(ipw|reg|dr|custom)&lt;/code>&lt;/td>
&lt;td>&lt;code>ipw&lt;/code>&lt;/td>
&lt;td>Treatment adjustment.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>panel(0|1)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>0 requests repeated cross sections.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>allowunbalanced(0|1)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>Chained mode refuses 0; ordinary mode keeps units observed at every date unless 1.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>bstrap(0|1)&lt;/code>, &lt;code>cband(0|1)&lt;/code>&lt;/td>
&lt;td>&lt;/td>
&lt;td>Accepted; the test always uses the bootstrap.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>biters(#)&lt;/code>, &lt;code>level(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1000&lt;/code>, &lt;code>95&lt;/code>&lt;/td>
&lt;td>Bootstrap draws and level of the critical value.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>pl(0|1)&lt;/code>, &lt;code>cores(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>0&lt;/code>, &lt;code>1&lt;/code>&lt;/td>
&lt;td>Only &lt;code>pl(0) cores(1)&lt;/code> is accepted; the test runs serially.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>signs(matname)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Bootstrap multipliers supplied as a matrix of -1 and +1.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>posting(matrix|state)&lt;/code>, &lt;code>store(name)&lt;/code>&lt;/td>
&lt;td>&lt;code>matrix&lt;/code>&lt;/td>
&lt;td>&lt;code>state&lt;/code> requires &lt;code>store()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>saving(filename)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Save for &lt;code>cdid_pretest_load&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The ordinary pretest accepts &lt;code>anticipation()&lt;/code>, &lt;code>baseperiod()&lt;/code>, &lt;code>fixweights()&lt;/code>, &lt;code>frame()&lt;/code> and its associated options, the missing-outcome options, &lt;code>imppooling()&lt;/code>, &lt;code>outcomepooling()&lt;/code>, &lt;code>workspace()&lt;/code>, &lt;code>chunk()&lt;/code> and &lt;code>workcap()&lt;/code> as inactive. &lt;code>r(inactive_options)&lt;/code> lists them whether specified or omitted. The note names those supplied in the command.&lt;/p>
&lt;h2 id="cdid_chain-options">cdid_chain options&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>cohort(numlist)&lt;/code>, &lt;code>time(numlist)&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Cells reported.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>pre&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>Include pretreatment and reference cells.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>weights&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>List the GMM weight of each comparison.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>tol(#)&lt;/code>&lt;/td>
&lt;td>&lt;code>1e-10&lt;/code>&lt;/td>
&lt;td>Weights below # in absolute value are treated as zero.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>saving(filename[, replace])&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Save a table as a dataset.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>table(summary|witness|weights)&lt;/code>&lt;/td>
&lt;td>&lt;code>summary&lt;/code>&lt;/td>
&lt;td>Table to save; requires &lt;code>saving()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>cdid_chain&lt;/code> is refused after &lt;code>dvar()&lt;/code> and in ordinary mode (error 198) and after the preset (error 498).&lt;/p>
&lt;h2 id="other-commands">Other commands&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Command and option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Description&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>cdid_nuisance&lt;/code> &lt;em>component&lt;/em>, &lt;code>block(id)&lt;/code>&lt;/td>
&lt;td>all blocks&lt;/td>
&lt;td>Component and block to display.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_diagnostics, detail&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>List each unavailable cell and bin.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_plot, group(numlist)&lt;/code>&lt;/td>
&lt;td>all&lt;/td>
&lt;td>Cohorts to plot.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_plot, cells&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>Plot the cells after &lt;code>estat&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_plot, saving()&lt;/code>, &lt;code>export()&lt;/code>, &lt;code>plotdata()&lt;/code>, &lt;code>replace&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Save the graph, export it with &lt;code>graph export&lt;/code>, or save the plotted values.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_export, type()&lt;/code>&lt;/td>
&lt;td>&lt;code>cells&lt;/code>&lt;/td>
&lt;td>&lt;code>cells&lt;/code>, &lt;code>aggregate&lt;/code>, &lt;code>units&lt;/code>, &lt;code>influence&lt;/code> or &lt;code>summary&lt;/code>; after &lt;code>dvar()&lt;/code>, &lt;code>cells&lt;/code> or &lt;code>aggregate&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_export, replace&lt;/code>&lt;/td>
&lt;td>off&lt;/td>
&lt;td>Overwrite the file.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_load, posting()&lt;/code>, &lt;code>workspace()&lt;/code>&lt;/td>
&lt;td>&lt;code>matrix&lt;/code>, &lt;code>1073741824&lt;/code>&lt;/td>
&lt;td>As for &lt;code>cdid&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_pretest_load, store()&lt;/code>, &lt;code>posting()&lt;/code>, &lt;code>workspace()&lt;/code>&lt;/td>
&lt;td>none, &lt;code>matrix&lt;/code>, &lt;code>1073741824&lt;/code>&lt;/td>
&lt;td>&lt;code>posting(state)&lt;/code> requires &lt;code>store()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="refusals">Refusals&lt;/h2>
&lt;p>Unless noted, refusals stop with error 198:&lt;/p>
&lt;ul>
&lt;li>&lt;code>crosspair&lt;/code> requires chained mode; &lt;code>rcs&lt;/code> with &lt;code>mode(chained)&lt;/code> is refused.&lt;/li>
&lt;li>&lt;code>iweight&lt;/code> together with &lt;code>wvar()&lt;/code>, and &lt;code>covars()&lt;/code> together with a covariate varlist, are refused.&lt;/li>
&lt;li>&lt;code>method(custom)&lt;/code> is refused with &lt;code>selmethod(imputation)&lt;/code> or &lt;code>selmethod(dr)&lt;/code> (error 459), with &lt;code>crosspair&lt;/code> and with &lt;code>gmmweighting(within)&lt;/code>.&lt;/li>
&lt;li>Ordinary &lt;code>cdid&lt;/code> refuses &lt;code>frame()&lt;/code> and its associated options, &lt;code>noconstant&lt;/code>, &lt;code>covars()&lt;/code> and &lt;code>panel()&lt;/code>.&lt;/li>
&lt;li>The preset requires the settings listed under &lt;a href="#chaining-and-designs">Chaining and designs&lt;/a>: unmet option settings are refused with error 198, and dates that are not consecutive positive integers with error 459. It also refuses &lt;code>missingreference(exclude)&lt;/code>.&lt;/li>
&lt;/ul>
&lt;p>The following are also refused: &lt;code>targets()&lt;/code> with &lt;code>targetcohorts()&lt;/code>; &lt;code>selconstant&lt;/code> with &lt;code>selcovars()&lt;/code>, &lt;code>frameselcovars()&lt;/code>, &lt;code>selnoconstant&lt;/code> or &lt;code>selzero&lt;/code>; &lt;code>ptstart()&lt;/code> with &lt;code>ptassumption(post)&lt;/code>; and &lt;code>ptassumption(all)&lt;/code> without &lt;code>ptstart()&lt;/code> (error 459).&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 18 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/inference/">Clustered inference, confidence bands, and pretrend tests&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/">Results reference&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Parallel trends</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/parallel-trends/</guid><description>&lt;p>In chained difference-in-differences (&lt;code>cdid&lt;/code>, Bellégo, Benatia and Dortet-Bernadet 2025; Callaway and Sant&amp;rsquo;Anna 2021), identifying treatment effects requires assuming that, in the absence of treatment, treated and control cohorts would have followed parallel average outcome trajectories conditional on covariates $X_i$.&lt;/p>
&lt;p>In Stata, four options govern how parallel trends and pre-treatment comparisons are defined:&lt;/p>
&lt;ul>
&lt;li>&lt;code>ptassumption(post|ctrl|all)&lt;/code> (default &lt;code>post&lt;/code>): selects the parallel-trends restrictions imposed in the GMM system; &lt;code>ctrl&lt;/code> adds common trends among the eligible control cohorts, and &lt;code>all&lt;/code> common trends of the target and control cohorts, from &lt;code>ptstart()&lt;/code>,&lt;/li>
&lt;li>&lt;code>ptstart(#)&lt;/code>: specifies the common calendar start date, required with &lt;code>ptassumption(all)&lt;/code>, optional with &lt;code>ptassumption(ctrl)&lt;/code> (where it defaults to the first study date), and not allowed with &lt;code>ptassumption(post)&lt;/code>,&lt;/li>
&lt;li>&lt;code>anticipation(#)&lt;/code> (default &lt;code>0&lt;/code>): sets the number of pre-treatment calendar periods in which units may anticipate treatment, fixing each cohort&amp;rsquo;s reference period $r(g)$ at the latest study date $d$ with $d &amp;lt; g - \text{anticipation}$ ($g - 1 - \text{anticipation}$ when the dates are consecutive integers),&lt;/li>
&lt;li>&lt;code>baseperiod(varying|universal)&lt;/code> (default &lt;code>varying&lt;/code>): independently controls how unrestricted pre-treatment comparisons (&lt;code>role == &amp;quot;pre&amp;quot;&lt;/code>) are parameterized and reported.&lt;/li>
&lt;/ul>
&lt;h2 id="1-post-treatment-parallel-trends-ptassumptionpost-default">1. Post-treatment parallel trends (&lt;code>ptassumption(post)&lt;/code>, default)&lt;/h2>
&lt;p>Under &lt;code>ptassumption(post)&lt;/code> (&lt;code>PT-post&lt;/code>), conditional parallel trends are assumed &lt;strong>from each cohort&amp;rsquo;s reference period $r(g)$ onward&lt;/strong>. Specifically, for every post-reference date pair $(s, t)$ with $r(g) \le s &amp;lt; t$ and control pool $K$:&lt;/p>
&lt;p>$$E[Y_t(0) - Y_s(0) \mid X, G = g] = E[Y_t(0) - Y_s(0) \mid X, G \in K]$$&lt;/p>
&lt;p>What about date pairs touching periods &lt;strong>before&lt;/strong> $r(g)$?&lt;/p>
&lt;ul>
&lt;li>Under &lt;code>ptassumption(post)&lt;/code>, pre-reference untreated differentials $\delta_{g, d \to d+1}$ for $d &amp;lt; r(g)$ are &lt;strong>unrestricted&lt;/strong> free parameters in the GMM system.&lt;/li>
&lt;li>Under the other assumptions on the comparisons, on observation and on the adjustment models, earlier differentials can enter the model without being restricted to zero. This is a statement about identification in the population, not about exact invariance in finite samples.&lt;/li>
&lt;/ul>
&lt;h3 id="comparisons-through-earlier-dates-under-ptassumptionpost">Comparisons through earlier dates under &lt;code>ptassumption(post)&lt;/code>&lt;/h3>
&lt;p>Even though pre-reference differentials are unrestricted under &lt;code>ptassumption(post)&lt;/code>, two-date comparisons starting before $r(g)$ are still used whenever their unrestricted differentials before the reference period cancel through an intermediate date:&lt;/p>
&lt;ul>
&lt;li>Suppose cohort $g = 3$ has reference period $r(3) = 2$, and units are observed on pairs $(1, 2)$ and $(1, 3)$.&lt;/li>
&lt;li>In the GMM design matrix $A$, the comparison on $(1, 2)$ loads on $\delta_{3, 1 \to 2}$, while the comparison on $(1, 3)$ loads on $\delta_{3, 1 \to 2} + \text{ATT}(3, 3)$.&lt;/li>
&lt;li>Taking the difference between the two moments cancels $\delta_{3, 1 \to 2}$:
$$E[Y_3 - Y_1] - E[Y_2 - Y_1] = E[Y_3 - Y_2]$$
and identifies $\text{ATT}(3, 3)$ without assuming parallel trends between $t = 1$ and $t = 2$.&lt;/li>
&lt;/ul>
&lt;h2 id="2-adding-pre-reference-restrictions-ptassumptionall-ptstart">2. Adding pre-reference restrictions (&lt;code>ptassumption(all) ptstart(#)&lt;/code>)&lt;/h2>
&lt;p>The Stata snippets on this page use the simulated panel and the global &lt;code>CDID_DEMO_BITERS&lt;/code> created by Sections 0 and 1 of the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/hands-on/">hands-on do-file&lt;/a>; run those sections first.&lt;/p>
&lt;p>When domain knowledge justifies parallel trends starting at an earlier calendar date $t_{\text{start}}$ common to all cohorts, specify &lt;code>ptassumption(all)&lt;/code> together with &lt;code>ptstart(#)&lt;/code>:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) controlgroup(nevertreated) ptassumption(all) ptstart(1) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;p>What &lt;code>ptassumption(all) ptstart(#)&lt;/code> changes, and what it keeps unchanged:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Keeps every PT-post condition and each cohort&amp;rsquo;s reference period $r(g)$:&lt;/strong> Post-treatment effects $\text{ATT}(g, t)$ ($t \ge g$) are still defined relative to each cohort&amp;rsquo;s reference period $r(g)$ ($t = 2$ for $g = 3$, $t = 4$ for $g = 5$).&lt;/li>
&lt;li>&lt;strong>Constrains the differentials from &lt;code>ptstart(#)&lt;/code> up to $r(g)$ to zero:&lt;/strong> Every differential on an untreated step between &lt;code>ptstart(#)&lt;/code> and $r(g)$ is constrained to zero in the GMM design matrix $A$. As a result, a comparison from $t = 1$ to $t = 3$ for cohort $g = 3$ directly loads on $\text{ATT}(3, 3)$ without needing to subtract a separate $(1, 2)$ comparison.&lt;/li>
&lt;li>&lt;strong>Remains a chained within-unit GMM estimator:&lt;/strong> &lt;code>ptassumption(all)&lt;/code> adds zero restrictions on the differentials to the chained GMM system, which uses the same within-unit comparisons. It does &lt;strong>not&lt;/strong> switch to a cross-sectional estimator, and it does &lt;strong>not&lt;/strong> guarantee smaller standard errors in every cell or in every finite sample draw (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/precision/">How to compare precision&lt;/a>, &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/pt-all-comparison/">Add PT-all restrictions&lt;/a>).&lt;/li>
&lt;li>&lt;strong>Validation:&lt;/strong>
&lt;ul>
&lt;li>&lt;code>ptstart(#)&lt;/code> is &lt;strong>required&lt;/strong> with &lt;code>ptassumption(all)&lt;/code> and must be one of the periods of the data.&lt;/li>
&lt;li>&lt;code>ptstart(#)&lt;/code> is &lt;strong>not allowed&lt;/strong> with &lt;code>ptassumption(post)&lt;/code>.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h3 id="choosing-ptstart">Choosing &lt;code>ptstart(#)&lt;/code>&lt;/h3>
&lt;p>Always choose &lt;code>ptassumption(all)&lt;/code> and &lt;code>ptstart(#)&lt;/code> substantively from institutional or domain knowledge &lt;strong>before&lt;/strong> inspecting point estimates, standard errors, or pretrend test $p$-values. Data-mining &lt;code>ptstart(#)&lt;/code> after viewing pretrend tests invalidates subsequent inference.&lt;/p>
&lt;h2 id="3-base-period-parameterization-baseperiodvaryinguniversal">3. Base-period parameterization (&lt;code>baseperiod(varying|universal)&lt;/code>)&lt;/h2>
&lt;p>Separately from &lt;code>ptassumption(post|all)&lt;/code>, the option &lt;code>baseperiod(varying|universal)&lt;/code> controls how unrestricted pre-treatment comparisons (&lt;code>role == &amp;quot;pre&amp;quot;&lt;/code>, where $t &amp;lt; g - \text{anticipation}$) are defined and reported in &lt;code>e(b)&lt;/code>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>&lt;code>baseperiod(varying)&lt;/code> (default):&lt;/strong> Reports consecutive pre-treatment step comparisons (comparing each pre-treatment period $t$ to the immediately preceding period in the stored calendar).&lt;/li>
&lt;li>&lt;strong>&lt;code>baseperiod(universal)&lt;/code>:&lt;/strong> Reports every non-reference pre-treatment period $t$ relative to the cohort&amp;rsquo;s fixed reference period $r(g)$.&lt;/li>
&lt;/ul>
&lt;p>Crucially, &lt;strong>pre-treatment cells (&lt;code>role == &amp;quot;pre&amp;quot;&lt;/code>) are never forced to zero in &lt;code>e(b)&lt;/code> by &lt;code>ptassumption(all)&lt;/code>&lt;/strong>: under both &lt;code>ptassumption(post)&lt;/code> and &lt;code>ptassumption(all)&lt;/code>, the reported pre-treatment cells remain direct unrestricted pre-period diagnostics.&lt;/p>
&lt;h2 id="4-how-the-row-space-condition-determines-cell-availability">4. How the row-space condition determines cell availability&lt;/h2>
&lt;p>The availability of each post-treatment effect is checked against the row space of the design. Pretreatment cells, which are direct comparisons, have their own support rules. Unsupported cells stay in the results with missing estimates and inference and a stated reason; &lt;code>e(b)&lt;/code> holds only the available estimates, mapped to cells by &lt;code>e(coef_map)&lt;/code>. Use &lt;code>cdid_diagnostics, detail&lt;/code> or &lt;code>cdid_export, type(cells)&lt;/code> to see every cell. Regularizing the covariance cannot create support.&lt;/p>
&lt;h2 id="5-pretrend-tests-under-each-choice">5. Pretrend tests under each choice&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Unconditional joint Wald pretrend test (&lt;code>e(wald_statistic)&lt;/code>, &lt;code>e(wald_df)&lt;/code>, &lt;code>e(wald_p)&lt;/code>):&lt;/strong> Jointly tests that all unrestricted pretreatment cells (&lt;code>role == &amp;quot;pre&amp;quot;&lt;/code>) equal zero. Because &lt;code>role == &amp;quot;pre&amp;quot;&lt;/code> cells remain unrestricted under &lt;code>ptassumption(all)&lt;/code>, the Wald test evaluates the exact same unrestricted pre-period null under both &lt;code>ptassumption(post)&lt;/code> and &lt;code>ptassumption(all)&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Standalone conditional pretrend test (&lt;code>cdid_pretest&lt;/code>):&lt;/strong> Tests that conditional pre-treatment mean comparisons equal zero across the covariate distribution on $F$ (&lt;code>r(CvM)&lt;/code>, &lt;code>r(CvMcval)&lt;/code>, &lt;code>r(CvMpval)&lt;/code>). &lt;code>cdid_pretest&lt;/code> evaluates direct pre-treatment pairs and therefore has no &lt;code>ptassumption()&lt;/code> or &lt;code>ptstart()&lt;/code> options (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/inference/">Inference&lt;/a>).&lt;/li>
&lt;/ul>
&lt;h2 id="6-example">6. Example&lt;/h2>
&lt;p>Section 3c of the hands-on do-file estimates the model under PT-all from period 1:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) controlgroup(nevertreated) ptassumption(all) ptstart(1) ///
biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;p>&lt;code>ptstart()&lt;/code> names one of the periods of the data. PT-all leaves the pretreatment cells, which serve as diagnostics, unrestricted. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/pt-all-comparison/">Add PT-all restrictions&lt;/a> for an example in which PT-all is false.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 13 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/change-imputation/">Impute actual changes for missing outcomes&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/pt-all-comparison/">Add PT-all restrictions&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Performance</title><link>https://www.davidbenatia.com/tools/cdid/stata/performance/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/performance/</guid><description>&lt;p>This page reports computation times of &lt;code>cdid&lt;/code> 1.0.0.0 on simulated incomplete panels, measured with the do-file shown below. The times describe one computer and one simulated design; they are not a benchmark against other software and say nothing about the statistical properties of the estimators. Run the same commands on your computer to obtain your own times.&lt;/p>
&lt;h2 id="what-was-measured">What was measured&lt;/h2>
&lt;p>The do-file simulates a staggered panel with three treated cohorts, never-treated units, five covariates and outcomes missing with a probability that depends on one covariate. It times complete &lt;code>cdid&lt;/code> calls, including data checks, estimation, influence functions, the multiplier bootstrap where requested, and the display and posting of results, for four corrections for missing outcomes and two panel sizes.&lt;/p>
&lt;pre>&lt;code class="language-stata">capture program drop perf_panel
program define perf_panel
args n
clear
set seed 20261116
quietly set obs `n'
generate id = _n
generate G = cond(runiform() &amp;lt; .3, 0, 2002 + floor(3 * runiform()))
forvalues k = 1/5 {
generate x`k' = rnormal()
}
quietly expand 6
bysort id: generate year = 2000 + _n
generate y = x1 + .5 * x2 + .2 * (year - 2000) + (G &amp;gt; 0 &amp;amp; year &amp;gt;= G) + rnormal()
quietly replace y = . if runiform() &amp;lt; invlogit(-1.5 + .5 * x1)
end
* One untimed call first, so that one-time loading costs are not timed
perf_panel 500
quietly cdid y x1-x5, ivar(id) time(year) gvar(G) bstrap(0) cband(0)
foreach n in 2000 8000 {
perf_panel `n'
timer clear
timer on 1
quietly cdid y x1-x5, ivar(id) time(year) gvar(G)
timer off 1
timer on 2
quietly cdid y x1-x5, ivar(id) time(year) gvar(G) selection(conditional_mtar)
timer off 2
timer on 3
quietly cdid y x1-x5, ivar(id) time(year) gvar(G) selection(conditional_mtar) selmethod(imputation)
timer off 3
timer on 4
quietly cdid y x1-x5, ivar(id) time(year) gvar(G) selection(conditional_mtar) selmethod(dr)
timer off 4
timer on 5
quietly cdid y x1-x5, ivar(id) time(year) gvar(G) selection(conditional_mtar) selmethod(dr) bstrap(0) cband(0)
timer off 5
display as text _n &amp;quot;Units: `n'&amp;quot;
timer list
}
display &amp;quot;processors: &amp;quot; c(processors) &amp;quot;, Stata &amp;quot; c(stata_version) &amp;quot;, &amp;quot; c(os) &amp;quot; &amp;quot; c(machine_type)
&lt;/code>&lt;/pre>
&lt;h2 id="results">Results&lt;/h2>
&lt;pre>&lt;code class="language-text">Units: 2000
1: 0.08 / 1 = 0.0840
2: 0.27 / 1 = 0.2660
3: 0.23 / 1 = 0.2300
4: 0.18 / 1 = 0.1820
5: 0.09 / 1 = 0.0910
Units: 8000
1: 0.25 / 1 = 0.2510
2: 0.30 / 1 = 0.3050
3: 0.19 / 1 = 0.1910
4: 0.31 / 1 = 0.3070
5: 0.24 / 1 = 0.2380
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">processors: 4, Stata 19.5, Unix Mac (Apple Silicon)
&lt;/code>&lt;/pre>
&lt;p>Timer 1 is the default fit (doubly robust treatment adjustment, no correction for missing outcomes, 1000 bootstrap draws); timers 2 to 4 add observation weighting, change imputation and the augmented correction; timer 5 repeats timer 4 with analytical standard errors. Each line gives the elapsed seconds of one call. Times this short vary from run to run and indicate orders of magnitude only.&lt;/p>
&lt;h2 id="controlling-memory-and-time">Controlling memory and time&lt;/h2>
&lt;p>&lt;code>workspace()&lt;/code> limits the memory used for the main numerical arrays (1 GiB by default), &lt;code>chunk()&lt;/code> the number of rows processed at once, and &lt;code>workcap()&lt;/code> the counted work; a fit that would exceed a limit is refused rather than truncated. &lt;code>posting(state)&lt;/code> keeps results that are too large for Stata matrices. Analytical standard errors (&lt;code>bstrap(0)&lt;/code>) avoid the bootstrap draws, and &lt;code>noinffunc&lt;/code> skips the influence functions when only point estimates are needed.&lt;/p>
&lt;hr>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Prepare your panel and unit table</title><link>https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/</guid><description>&lt;p>Before running &lt;code>cdid&lt;/code>, check that the data in memory and the optional unit table in &lt;code>frame()&lt;/code> have the structure the estimators expect: identifiers, dates, cohorts, covariates and sampling weights. To check the patterns of missing outcomes and the coverage of pairs of dates, see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/investigate-missingness/">Investigate missingness and data structure&lt;/a>.&lt;/p>
&lt;h2 id="if-treatment-can-stop-and-restart">If treatment can stop and restart&lt;/h2>
&lt;p>This page describes staggered adoption with &lt;code>gvar()&lt;/code>. For a binary treatment that units enter and leave, supply &lt;code>dvar()&lt;/code>, the treatment status at every date, with one row for every unit at every date, including dates with missing outcomes; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/switching/#what-your-input-needs">When treatment can stop and restart&lt;/a>.&lt;/p>
&lt;h2 id="core-requirements">Core requirements&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> expects long data with one observation per unit and date:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Element&lt;/th>
&lt;th>Option&lt;/th>
&lt;th>Requirement&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Outcome&lt;/td>
&lt;td>&lt;code>depvar&lt;/code>&lt;/td>
&lt;td>Numeric. A missing value (&lt;code>.&lt;/code>, &lt;code>.a&lt;/code> to &lt;code>.z&lt;/code>) is an unobserved outcome, like an omitted row.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Unit identifier&lt;/td>
&lt;td>&lt;code>ivar()&lt;/code>&lt;/td>
&lt;td>Numeric or string in chained mode, numeric in ordinary mode. Nonmissing, and unique with the date (&lt;code>isid id year&lt;/code>).&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Date&lt;/td>
&lt;td>&lt;code>time()&lt;/code>&lt;/td>
&lt;td>Numeric and finite. Dates need not be consecutive (for example 2014, 2016, 2018). Durations used by pooled outcome regressions count positions in the sorted list of study dates, not differences between date values.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Cohort&lt;/td>
&lt;td>&lt;code>gvar()&lt;/code>&lt;/td>
&lt;td>First treatment date, constant within unit, nonnegative and nonmissing. Code units never treated as &lt;code>0&lt;/code>, not as missing.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>By default, every treated cohort whose treatment date is on or before the last study date is a target. A cohort treated at or before the first study date has no pretreatment date, and its effects are reported as unavailable.&lt;/p>
&lt;h3 id="never-impute-zero-for-missing-outcomes">Never impute zero for missing outcomes&lt;/h3>
&lt;p>Keep a missing outcome missing. Replacing it with zero, a carried-forward value or an interpolation creates changes that were never observed, and no option of &lt;code>cdid&lt;/code> can undo that. Rows with a missing outcome may be kept or dropped: both representations define the same observed outcomes. Keep them when they carry covariates or weights needed at that date (see &lt;a href="#reference-dates-for-covariates-that-change-within-a-unit">Reference dates&lt;/a>).&lt;/p>
&lt;h2 id="the-unit-table-frame-and-unit-observation-roles">The unit table (&lt;code>frame()&lt;/code>) and unit observation roles&lt;/h2>
&lt;h3 id="study-population-versus-the-data-in-memory">Study population versus the data in memory&lt;/h3>
&lt;p>The study population is the set of units whose effects the analysis describes. Without &lt;code>frame()&lt;/code>, the units present in the data form it, so a unit whose rows were all dropped disappears from it. &lt;code>frame(name)&lt;/code> supplies a Stata frame with one row per study unit, including units with one or no observed outcome:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Option&lt;/th>
&lt;th>Default&lt;/th>
&lt;th>Requirement&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>frame(name)&lt;/code>&lt;/td>
&lt;td>none&lt;/td>
&lt;td>Existing frame with exactly one row per study unit.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>frameivar(name)&lt;/code>&lt;/td>
&lt;td>the &lt;code>ivar()&lt;/code> name&lt;/td>
&lt;td>Unique, nonmissing identifier; every unit of the estimation sample must appear in the frame.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>framegvar(name)&lt;/code>&lt;/td>
&lt;td>not read&lt;/td>
&lt;td>Cohort in the frame; must agree with &lt;code>gvar()&lt;/code> for units in the data.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>framecovars(varlist)&lt;/code>&lt;/td>
&lt;td>not read&lt;/td>
&lt;td>Time-invariant covariates in the frame.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>frameselcovars(varlist)&lt;/code>&lt;/td>
&lt;td>not read&lt;/td>
&lt;td>Time-invariant observation-model covariates in the frame.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>framewvar(name)&lt;/code>&lt;/td>
&lt;td>not read&lt;/td>
&lt;td>Positive unit weights in the frame.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>framecluster(name)&lt;/code>&lt;/td>
&lt;td>not read&lt;/td>
&lt;td>Cluster identifiers in the frame.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Only &lt;code>frameivar()&lt;/code> has a default. The other columns are read from the frame only when you name them, even if the frame has variables with the same names as in the data.&lt;/p>
&lt;h3 id="roles-of-units-with-zero-one-or-repeated-observations">Roles of units with zero, one or repeated observations&lt;/h3>
&lt;p>&lt;code>cdid&lt;/code> distinguishes three nested sets of units: the study population $F$; the units with at least one observed outcome, $B$; and the units with at least two, $A$, with $A \subseteq B \subseteq F$. &lt;code>cdid_diagnostics&lt;/code> reports their sizes. A unit observed once or never supplies no change, but it belongs to its cohort: it enters the cohort shares used by &lt;code>estat&lt;/code>, the observation models fitted with &lt;code>seluniverse(F)&lt;/code>, the averages of imputed changes and the influence functions (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>).&lt;/p>
&lt;h2 id="panel-mode-and-allowunbalanced">Panel mode and &lt;code>allowunbalanced&lt;/code>&lt;/h2>
&lt;p>Chained mode, the default with panel data, uses every unit with gaps; &lt;code>allowunbalanced&lt;/code> changes nothing there. Ordinary mode keeps only units observed at every date unless &lt;code>allowunbalanced&lt;/code> is specified, in which case it uses repeated cross-section estimators; &lt;code>rcs&lt;/code> declares repeated cross sections. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-did/#incomplete-panels-in-ordinary-and-chained-mode">Moving from did and csdid&lt;/a>.&lt;/p>
&lt;h2 id="static-versus-changing-covariates-and-sampling-weights">Static versus changing covariates and sampling weights&lt;/h2>
&lt;h3 id="static-covariates-and-weights">Static covariates and weights&lt;/h3>
&lt;p>Covariates and weights that are constant within units need no date. They must be nonmissing for every unit used in estimation; with &lt;code>frame()&lt;/code>, supply them for every unit of the frame. Factor-variable notation (&lt;code>i.region&lt;/code>, &lt;code>c.x##c.z&lt;/code>) is accepted in the covariates and in &lt;code>selcovars()&lt;/code>.&lt;/p>
&lt;h3 id="reference-dates-for-covariates-that-change-within-a-unit">Reference dates for covariates that change within a unit&lt;/h3>
&lt;p>A cohort&amp;rsquo;s reference date is the latest study date before its treatment date, less the &lt;code>anticipation()&lt;/code> periods: the latest date $d$ with $d + \text{anticipation} &amp;lt; g$. Covariates that vary over time are read at the reference date of each target cohort for its post-treatment comparisons, and at the earlier date of each pretrend comparison. With &lt;code>crosspair&lt;/code>, every comparison of cohort $g$, including those of its control cohorts, reads covariates at $g$&amp;rsquo;s reference date. Covariates are never carried forward, substituted, imputed or read from another date. A known covariate on a row whose outcome is missing is valid input.&lt;/p>
&lt;p>When a required covariate is missing at the date where a cohort&amp;rsquo;s comparisons read it, &lt;code>missingreference()&lt;/code> decides:&lt;/p>
&lt;ul>
&lt;li>&lt;code>missingreference(exclude)&lt;/code>, the default, warns and excludes the affected units from that cohort&amp;rsquo;s comparisons only, in treated and comparison roles. The unit still contributes to other cohorts whose reference covariates it has. It keeps its row in the influence functions, and the number of units is unchanged. If treated units are excluded, the cohort&amp;rsquo;s effects describe its remaining treated units, and &lt;code>estat&lt;/code> weights the cohort by those units. A pretrend comparison whose own earlier-date covariate is missing is reported as unavailable; the main comparisons are unchanged, and the joint pretrend Wald test is then not computed.&lt;/li>
&lt;li>&lt;code>missingreference(error)&lt;/code> stops with error 459 and lists up to five missing values with the unit, the date, the variable and the comparison that needs it.&lt;/li>
&lt;/ul>
&lt;p>&lt;code>missingreference()&lt;/code> covers covariates only. With &lt;code>fixweights()&lt;/code>, every unit used needs a positive weight at its anchor date, whatever &lt;code>missingreference()&lt;/code> says; a missing weight there stops &lt;code>cdid&lt;/code> with error 459 and a message naming the unit, the date and the variable.&lt;/p>
&lt;p>When no required value is missing, both settings give the same results. Time-invariant covariates keep their own rule: they must be complete for the units used. &lt;code>cdid_pretest&lt;/code> always stops when a required covariate is missing.&lt;/p>
&lt;p>The example below has 300 units over years 1 to 4, cohorts first treated in years 3 and 4, and never-treated units. Cohort 3 reads covariates in year 2, cohort 4 in year 3.&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261116
set obs 300
generate id = _n
generate G = cond(mod(id, 3) == 0, 3, cond(mod(id, 3) == 1, 4, 0))
expand 4
bysort id: generate year = _n
generate x = rnormal() + 0.2 * year
generate y = 0.5 * x + 0.3 * year + (G &amp;gt; 0 &amp;amp; year &amp;gt;= G) + rnormal()
* Unit 3 (cohort 3) has no year-2 outcome, but its year-2 covariate is known:
* the row stays, with y missing and x supplied.
replace y = . if id == 3 &amp;amp; year == 2
* Unit 6 (cohort 3) has an unknown year-2 covariate.
replace x = . if id == 6 &amp;amp; year == 2
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-stata">cdid y x, ivar(id) time(year) gvar(G) bstrap(0) cband(0)
matrix list e(reference_eligibility)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Warning: Excluded units with missing reference covariates from the affected cohort comparisons.
Counts across the supplied units at each reference date, including units outside the
comparison groups: cohort 3 (date 2): 1 treated, 0 never-treated, 0 from other cohorts.
See e(reference_eligibility) for details. If you know a missing covariate, supply it on
its unit-date row, with a missing value for a missing outcome.
Chained difference-in-differences Number of units = 300
Method: doubly robust (dr) Number of cells = 6
GMM weighting: optimal
Control group: never treated; base period: varying
------------------------------------------------------------------------------
Group Time Role ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
3 2 pre -.1787712 .2121536 -.5945847 .2370422
3 3 post 1.171452 .2155867 .74891 1.593994
3 4 post 1.1487 .2301844 .6975466 1.599853
4 2 pre .06346298 .2005939 -.3296938 .4566197
4 3 pre -.09102793 .2350894 -.5517947 .3697388
4 4 post 1.090736 .2152742 .6688067 1.512666
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
Pretrend Wald test (pre-treatment cells): chi2(3) = 1.79, Prob &amp;gt; chi2 = 0.6163
Restricted comparisons for cohort(s) 3. See e(reference_eligibility).
Effects for cohort 3 cover 99 of 100 treated units.
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">e(reference_eligibility)[2,8]
cohort reference_~e n_treated n_treated_~e n_treated_~d n_never_tr~d
g3 3 2 100 99 1 0
g4 4 3 100 100 0 0
n_other_co~d restricted
g3 0 1
g4 0 0
&lt;/code>&lt;/pre>
&lt;p>Unit 3 is used: its year-2 covariate is known, and its changes between the years in which its outcome is observed enter the comparisons. Unit 6 is excluded from cohort 3&amp;rsquo;s comparisons. In &lt;code>e(reference_eligibility)&lt;/code>, &lt;code>n_treated_excluded&lt;/code> counts the cohort-3 units that lack a required covariate in year 2; the effects of cohort 3 describe the &lt;code>n_treated_eligible&lt;/code> remaining units. &lt;code>n_never_treated_excluded&lt;/code> and &lt;code>n_other_cohort_excluded&lt;/code> count units that cannot serve as comparisons for cohort 3; the counts include units outside the comparison groups. Cohort 4 is unrestricted. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/#covariates-missing-at-a-reference-date">Results&lt;/a> lists the other stored results.&lt;/p>
&lt;p>The strict rule stops instead:&lt;/p>
&lt;pre>&lt;code class="language-stata">capture noisily cdid y x, ivar(id) time(year) gvar(G) bstrap(0) cband(0) missingreference(error)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Missing required reference covariate values (time-varying covariates are never carried forward, substituted or deleted): id 6, date 2, variable x, support (1-&amp;gt;2, cohort 3) of post link 1 (target 3). Supply each missing covariate on its unit-date row; the outcome may be missing on that row.
&lt;/code>&lt;/pre>
&lt;h3 id="add-a-known-reference-covariate-row">Add a known reference covariate row&lt;/h3>
&lt;p>If you know a missing covariate, supply it on its unit-date row, with a missing outcome if the outcome is missing. If the row exists, fill the covariate. If the row is absent, add it, with every other required field (cohort, weights, clusters). Continuing the example:&lt;/p>
&lt;pre>&lt;code class="language-stata">* Suppose unit 6's year-2 covariate becomes known from another source.
local x_year2 = 0.42
replace x = `x_year2' if id == 6 &amp;amp; year == 2
* Unit 9 (cohort 3) has no year-2 row at all, and its year-2 covariate is known.
drop if id == 9 &amp;amp; year == 2
local x9_year2 = 0.15
set obs `=_N + 1'
replace id = 9 in L
replace year = 2 in L
replace G = 3 in L
replace y = . in L
replace x = `x9_year2' in L
cdid y x, ivar(id) time(year) gvar(G) bstrap(0) cband(0)
display &amp;quot;`e(reference_status)'&amp;quot;
&lt;/code>&lt;/pre>
&lt;p>The fit now has no restricted cohort (&lt;code>e(reference_status)&lt;/code> is &lt;code>unrestricted&lt;/code>), and no warning is displayed. For a variable such as age, a recorded date of birth can supply the reference value if it determines age at the date the analysis uses. If a value is unknown, the default excludes the unit from the comparisons of the cohort that needs it.&lt;/p>
&lt;h3 id="changing-sampling-weights-and-fixweights">Changing sampling weights and &lt;code>fixweights()&lt;/code>&lt;/h3>
&lt;p>Supply positive sampling weights with &lt;code>[iweight = w]&lt;/code> or &lt;code>wvar(w)&lt;/code>, not both, and with &lt;code>framewvar()&lt;/code> when &lt;code>frame()&lt;/code> is used. Chained estimation uses one weight per unit. If weights vary within units, declare the rule with &lt;code>fixweights(first_period)&lt;/code>, which uses each unit&amp;rsquo;s weight at the first study date, or &lt;code>fixweights(base_period)&lt;/code>, which uses its weight at each target cohort&amp;rsquo;s reference date. The weight must be observed at that date; &lt;code>cdid&lt;/code> does not use the weight of another date. Without &lt;code>fixweights()&lt;/code>, weights that vary within units are refused. Weights are not allowed with &lt;code>preset(cohort_time_fe)&lt;/code> or &lt;code>dvar()&lt;/code>.&lt;/p>
&lt;h2 id="outcome-covariates-versus-observation-covariates">Outcome covariates versus observation covariates&lt;/h2>
&lt;p>The varlist (or &lt;code>covars()&lt;/code>) holds the covariates of the treatment and outcome models and of change imputation. &lt;code>selcovars()&lt;/code> gives the observation logits of &lt;code>selection(conditional_mtar)&lt;/code> their own covariates; by default they are the outcome covariates. &lt;code>selconstant&lt;/code> requests intercept-only observation logits, &lt;code>selnoconstant&lt;/code> removes the intercept, and &lt;code>selzero&lt;/code> uses no observation design. See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/observation-models/">Choose an observation model&lt;/a>.&lt;/p>
&lt;h2 id="separation-collinearity-and-covariance">Separation, collinearity and covariance&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Separation.&lt;/strong> A treatment or observation logit with no finite solution, for example because a covariate value perfectly predicts treatment within a comparison, stops the fit or makes the affected cells unavailable. Coarsen the covariate, pool the slopes (&lt;code>selpooling()&lt;/code>), or remove it.&lt;/li>
&lt;li>&lt;strong>Collinearity.&lt;/strong> Exactly redundant covariates in an outcome or imputation regression are dropped when they are exactly collinear on every row used to fit and to predict, as in R; other rank deficiencies are refused with error 459 and a message naming the regression.&lt;/li>
&lt;li>&lt;strong>Covariance regularization.&lt;/strong> &lt;code>condition()&lt;/code> and &lt;code>ridge()&lt;/code> regularize a nearly singular moment covariance in the GMM weighting. This concerns weighting, not identification: it does not make an unidentified effect available (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/gmm/">GMM weighting&lt;/a>).&lt;/li>
&lt;/ul>
&lt;h2 id="resource-controls">Resource controls&lt;/h2>
&lt;p>&lt;code>workspace()&lt;/code> limits the memory used, &lt;code>chunk()&lt;/code> the number of rows processed at once and &lt;code>workcap()&lt;/code> the counted work. A fit that would exceed a limit is refused rather than truncated. &lt;code>posting(state)&lt;/code> keeps results too large for Stata matrices; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/user-results/">Working with results&lt;/a>.&lt;/p>
&lt;h2 id="checklist">Checklist&lt;/h2>
&lt;p>On the data of the example above:&lt;/p>
&lt;pre>&lt;code class="language-stata">assert !missing(id, year, G)
isid id year
bysort id (year): assert G == G[1]
count if missing(y)
count if missing(x)
&lt;/code>&lt;/pre>
&lt;p>&lt;code>count if missing(x)&lt;/code> counts the observations with a missing covariate, which may be needed at a reference date. With a unit table, also check it inside the frame, for example &lt;code>frame units: isid id&lt;/code>.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 6 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/precision/">How to compare precision&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/">Treatment adjustment&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Results reference</title><link>https://www.davidbenatia.com/tools/cdid/stata/reference/results/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/reference/results/</guid><description>&lt;p>This page describes what each command stores, how unavailable effects and uncertainty are reported, and how results are saved. The help file of each command lists its stored results in Stata&amp;rsquo;s format. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/user-results/">Working with results&lt;/a> shows how results move between commands.&lt;/p>
&lt;h2 id="results-of-cdid-with-gvar">Results of cdid with gvar()&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> posts its results in &lt;code>e()&lt;/code>. The display reports the available cells; every requested cell, including unavailable ones, is kept with the results and written by &lt;code>cdid_export, type(cells)&lt;/code>.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(N)&lt;/code>&lt;/td>
&lt;td>number of units in the study population&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_full)&lt;/code>&lt;/td>
&lt;td>number of units in the study population, the scale of &lt;code>e(V_asymptotic)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_cells)&lt;/code>&lt;/td>
&lt;td>number of group-time cells of the fit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_targets)&lt;/code>&lt;/td>
&lt;td>number of rows of the results table, including unavailable and reference cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_posted)&lt;/code>&lt;/td>
&lt;td>number of estimates in &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(clustered)&lt;/code>&lt;/td>
&lt;td>1 if cluster() was specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_clust)&lt;/code>&lt;/td>
&lt;td>number of clusters, with cluster()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(point_only)&lt;/code>&lt;/td>
&lt;td>1 if only point estimates were computed (noinffunc)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(level)&lt;/code>&lt;/td>
&lt;td>confidence level&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(alpha)&lt;/code>&lt;/td>
&lt;td>1 - &lt;code>e(level)&lt;/code>/100&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(B_requested)&lt;/code>&lt;/td>
&lt;td>bootstrap draws requested&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(bstrap_requested)&lt;/code>&lt;/td>
&lt;td>value of bstrap()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cband_requested)&lt;/code>&lt;/td>
&lt;td>value of cband()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(critical_value)&lt;/code>&lt;/td>
&lt;td>critical value of the reported intervals or bands&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(normal_critical_value)&lt;/code>&lt;/td>
&lt;td>normal critical value at &lt;code>e(level)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_statistic)&lt;/code>&lt;/td>
&lt;td>pretrend Wald statistic&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_df)&lt;/code>&lt;/td>
&lt;td>its degrees of freedom&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_p)&lt;/code>&lt;/td>
&lt;td>its p-value&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_N_clust)&lt;/code>&lt;/td>
&lt;td>clusters used by the Wald test, with cluster()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(anticipation)&lt;/code>&lt;/td>
&lt;td>periods of anticipation&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(cmd)&lt;/code>&lt;/td>
&lt;td>cdid&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cmdline)&lt;/code>&lt;/td>
&lt;td>command as typed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(title)&lt;/code>&lt;/td>
&lt;td>title of the output&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(mode)&lt;/code>&lt;/td>
&lt;td>chained&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(depvar)&lt;/code>&lt;/td>
&lt;td>name of the outcome&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ivar)&lt;/code>&lt;/td>
&lt;td>unit identifier&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(time)&lt;/code>&lt;/td>
&lt;td>date variable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(gvar)&lt;/code>&lt;/td>
&lt;td>cohort variable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(covariates)&lt;/code>&lt;/td>
&lt;td>covariates, as typed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(clustvar)&lt;/code>&lt;/td>
&lt;td>cluster variable, with cluster()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(method)&lt;/code>&lt;/td>
&lt;td>treatment adjustment&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(control_group)&lt;/code>&lt;/td>
&lt;td>comparison group&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(base_period)&lt;/code>&lt;/td>
&lt;td>base period&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(pt_assumption)&lt;/code>&lt;/td>
&lt;td>parallel trends assumption&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(gmm_weighting)&lt;/code>&lt;/td>
&lt;td>GMM weighting&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(gmm_covariance)&lt;/code>&lt;/td>
&lt;td>covariance regularization&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(outcome_pooling)&lt;/code>&lt;/td>
&lt;td>outcome-regression pooling&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(imputation_pooling)&lt;/code>&lt;/td>
&lt;td>imputation pooling, when active&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection)&lt;/code>&lt;/td>
&lt;td>assumption about missing outcomes, as specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_canonical)&lt;/code>&lt;/td>
&lt;td>the same, in canonical form&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_est_method)&lt;/code>&lt;/td>
&lt;td>correction for missing outcomes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_model)&lt;/code>&lt;/td>
&lt;td>observation model&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_pooling)&lt;/code>&lt;/td>
&lt;td>observation-model pooling&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_universe)&lt;/code>&lt;/td>
&lt;td>units that fit the observation model&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_justification)&lt;/code>&lt;/td>
&lt;td>text of seljustification(), when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cross_pair)&lt;/code>&lt;/td>
&lt;td>crosspair, when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(preset)&lt;/code>&lt;/td>
&lt;td>cohort_time_fe, when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(missing_reference)&lt;/code>&lt;/td>
&lt;td>exclude or error (not with the preset)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_status)&lt;/code>&lt;/td>
&lt;td>restricted, auxiliary_unavailable, or unrestricted (not with the preset)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_restricted)&lt;/code>&lt;/td>
&lt;td>cohorts whose comparisons were restricted, when any&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_variables)&lt;/code>&lt;/td>
&lt;td>covariates whose reference values were checked, when comparisons were restricted&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(inactive_options)&lt;/code>&lt;/td>
&lt;td>options that have no effect under this specification, specified or not&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(callback)&lt;/code>&lt;/td>
&lt;td>callback(), with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(payload)&lt;/code>&lt;/td>
&lt;td>payload(), with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wtype)&lt;/code>&lt;/td>
&lt;td>weight type, with weights&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wexp)&lt;/code>&lt;/td>
&lt;td>weight expression, with weights&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(nuisance)&lt;/code>&lt;/td>
&lt;td>availability of the reports kept, with keepnuisance&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(vce)&lt;/code>&lt;/td>
&lt;td>analytic, bootstrap, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(vcetype)&lt;/code>&lt;/td>
&lt;td>Bootstrap, with the multiplier bootstrap&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(band)&lt;/code>&lt;/td>
&lt;td>pointwise, simultaneous, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(inference_rule)&lt;/code>&lt;/td>
&lt;td>how bstrap() and cband() were applied, in words&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(rng)&lt;/code>&lt;/td>
&lt;td>source of the bootstrap multipliers, in words&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(result_kind)&lt;/code>&lt;/td>
&lt;td>cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(result_status)&lt;/code>&lt;/td>
&lt;td>status of the results&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(inference_status)&lt;/code>&lt;/td>
&lt;td>status of the inference&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_status)&lt;/code>&lt;/td>
&lt;td>status of the pretrend Wald test&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_reason)&lt;/code>&lt;/td>
&lt;td>why the Wald test was not computed, when it was not&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(warning)&lt;/code>&lt;/td>
&lt;td>warnings, when any&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(posting_mode)&lt;/code>&lt;/td>
&lt;td>matrix or state&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(posting_reason)&lt;/code>&lt;/td>
&lt;td>description of what &lt;code>e(b)&lt;/code> holds&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(coefficient_map)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(coef_map)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(covariance_scale)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(V)&lt;/code> and &lt;code>e(V_asymptotic)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se_scale)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(se)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(sample_scope)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(sample)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(state_token)&lt;/code>&lt;/td>
&lt;td>reference to the stored results used by estat and the postestimation commands&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(state_file)&lt;/code>&lt;/td>
&lt;td>file written by saving(), when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(estat_cmd)&lt;/code>&lt;/td>
&lt;td>cdid_estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(properties)&lt;/code>&lt;/td>
&lt;td>b V, or b with noinffunc&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Matrices&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(b)&lt;/code>&lt;/td>
&lt;td>available estimates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V)&lt;/code>&lt;/td>
&lt;td>analytical covariance of &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V_asymptotic)&lt;/code>&lt;/td>
&lt;td>&lt;code>e(N_full)&lt;/code> times &lt;code>e(V)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se)&lt;/code>&lt;/td>
&lt;td>reported standard errors&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(analytic_se)&lt;/code>&lt;/td>
&lt;td>analytical standard errors&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ci)&lt;/code>&lt;/td>
&lt;td>reported intervals or bands (2 x k)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ci_pointwise)&lt;/code>&lt;/td>
&lt;td>pointwise intervals (2 x k)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(coef_map)&lt;/code>&lt;/td>
&lt;td>cell of each estimate in &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_eligibility)&lt;/code>&lt;/td>
&lt;td>eligible and excluded units by target cohort, when comparisons were restricted&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_contexts)&lt;/code>&lt;/td>
&lt;td>excluded units by reference date, when comparisons were restricted&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_aux_unavailable)&lt;/code>&lt;/td>
&lt;td>unavailable pretrend comparisons, when any&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Functions&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(sample)&lt;/code>&lt;/td>
&lt;td>marks the input rows of the units in the study population, including rows with a missing outcome; units excluded from the comparisons of a cohort, for example under missingreference(exclude), remain marked&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>With noinffunc, &lt;code>e(V)&lt;/code> and &lt;code>e(V_asymptotic)&lt;/code> are not posted and &lt;code>e(point_only)&lt;/code> is 1. With posting(matrix) and at least one available cell, &lt;code>e(se)&lt;/code>, &lt;code>e(analytic_se)&lt;/code>, &lt;code>e(ci)&lt;/code>, and &lt;code>e(ci_pointwise)&lt;/code> have missing entries and &lt;code>e(properties)&lt;/code> is b; with posting(state), no matrix is posted and &lt;code>e(properties)&lt;/code> is empty.&lt;/p>
&lt;p>&lt;code>e(sample)&lt;/code> marks the observations used: in chained mode it includes rows whose outcome is missing, because they determine when each unit is observed. &lt;code>cdid_load&lt;/code> does not set it.&lt;/p>
&lt;h3 id="ordinary-mode">Ordinary mode&lt;/h3>
&lt;p>In ordinary mode, &lt;code>cdid&lt;/code> stores the following; the chained-mode settings macros are not posted.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(N)&lt;/code>&lt;/td>
&lt;td>number of units used&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_full)&lt;/code>&lt;/td>
&lt;td>the same, the scale of &lt;code>e(V_asymptotic)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_cells)&lt;/code>&lt;/td>
&lt;td>number of group-time cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_targets)&lt;/code>&lt;/td>
&lt;td>number of rows of the results table&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_posted)&lt;/code>&lt;/td>
&lt;td>number of estimates in &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(clustered)&lt;/code>&lt;/td>
&lt;td>1 when the reported inference uses clusters&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_clust)&lt;/code>&lt;/td>
&lt;td>number of clusters, when clustered&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(point_only)&lt;/code>&lt;/td>
&lt;td>1 if only point estimates were computed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(level)&lt;/code>&lt;/td>
&lt;td>confidence level&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(alpha)&lt;/code>&lt;/td>
&lt;td>1 - &lt;code>e(level)&lt;/code>/100&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(B_requested)&lt;/code>&lt;/td>
&lt;td>bootstrap draws requested&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(bstrap)&lt;/code>&lt;/td>
&lt;td>value of bstrap()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cband)&lt;/code>&lt;/td>
&lt;td>value of cband()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(critical_value)&lt;/code>&lt;/td>
&lt;td>critical value of the reported intervals or bands&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(normal_critical_value)&lt;/code>&lt;/td>
&lt;td>normal critical value at &lt;code>e(level)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_statistic)&lt;/code>&lt;/td>
&lt;td>pretrend Wald statistic&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_df)&lt;/code>&lt;/td>
&lt;td>its degrees of freedom&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_p)&lt;/code>&lt;/td>
&lt;td>its p-value&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_p_unrounded)&lt;/code>&lt;/td>
&lt;td>its p-value before rounding&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(cmd)&lt;/code>&lt;/td>
&lt;td>cdid&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cmdline)&lt;/code>&lt;/td>
&lt;td>command as typed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(title)&lt;/code>&lt;/td>
&lt;td>title of the output&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(mode)&lt;/code>&lt;/td>
&lt;td>ordinary&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(depvar)&lt;/code>&lt;/td>
&lt;td>name of the outcome&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ivar)&lt;/code>&lt;/td>
&lt;td>unit identifier&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(time)&lt;/code>&lt;/td>
&lt;td>date variable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(gvar)&lt;/code>&lt;/td>
&lt;td>cohort variable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(covariates)&lt;/code>&lt;/td>
&lt;td>covariates, as typed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(clustvar)&lt;/code>&lt;/td>
&lt;td>cluster variable used for inference, when clustered&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(method)&lt;/code>&lt;/td>
&lt;td>treatment adjustment&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(inactive_options)&lt;/code>&lt;/td>
&lt;td>accepted options that have no effect in ordinary mode, specified or not&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(callback)&lt;/code>&lt;/td>
&lt;td>callback(), with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(payload)&lt;/code>&lt;/td>
&lt;td>payload(), with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(vce)&lt;/code>&lt;/td>
&lt;td>analytic, bootstrap, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(vcetype)&lt;/code>&lt;/td>
&lt;td>Bootstrap, with the multiplier bootstrap&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(band)&lt;/code>&lt;/td>
&lt;td>pointwise, simultaneous, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(inference_rule)&lt;/code>&lt;/td>
&lt;td>how bstrap() and cband() were applied, in words&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(result_kind)&lt;/code>&lt;/td>
&lt;td>ordinary_cells (ordinary_simple, &amp;hellip; after estat)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_status)&lt;/code>&lt;/td>
&lt;td>status of the pretrend Wald test&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(wald_reason)&lt;/code>&lt;/td>
&lt;td>cells used by the Wald test, or why it was not computed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(conditional_test_status)&lt;/code>&lt;/td>
&lt;td>status of the conditional pretest in this result&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(warning)&lt;/code>&lt;/td>
&lt;td>warnings, when any&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(posting_mode)&lt;/code>&lt;/td>
&lt;td>matrix or state&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(covariance_scale)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(V)&lt;/code>, &lt;code>e(V_asymptotic)&lt;/code>, and &lt;code>e(V_did)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se_scale)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(se)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(sample_scope)&lt;/code>&lt;/td>
&lt;td>description of &lt;code>e(sample)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(state_token)&lt;/code>&lt;/td>
&lt;td>reference to the stored results used by estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(estat_cmd)&lt;/code>&lt;/td>
&lt;td>cdid_estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(properties)&lt;/code>&lt;/td>
&lt;td>b V&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Matrices&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(b)&lt;/code>&lt;/td>
&lt;td>available estimates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V)&lt;/code>&lt;/td>
&lt;td>covariance of &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V_asymptotic)&lt;/code>&lt;/td>
&lt;td>&lt;code>e(N_full)&lt;/code> times &lt;code>e(V)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V_did)&lt;/code>&lt;/td>
&lt;td>covariance R&amp;rsquo;s att_gt() reports as V_analytical, divided by &lt;code>e(N_full)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V_did_asymptotic)&lt;/code>&lt;/td>
&lt;td>covariance R&amp;rsquo;s att_gt() reports as V_analytical&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se)&lt;/code>&lt;/td>
&lt;td>reported standard errors&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(analytic_se)&lt;/code>&lt;/td>
&lt;td>analytical standard errors&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ci)&lt;/code>&lt;/td>
&lt;td>reported intervals or bands (2 x k)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ci_pointwise)&lt;/code>&lt;/td>
&lt;td>pointwise intervals (2 x k)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(coef_map)&lt;/code>&lt;/td>
&lt;td>cell of each estimate in &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Functions&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(sample)&lt;/code>&lt;/td>
&lt;td>marks the observations used&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="unavailable-effects">Unavailable effects&lt;/h2>
&lt;p>An unavailable cell has missing estimates and inference and a reason, written by &lt;code>cdid_export, type(cells)&lt;/code> in the variable &lt;code>reason&lt;/code> and listed by &lt;code>cdid_diagnostics, detail&lt;/code>. With &lt;code>posting(matrix)&lt;/code>, only available estimates enter &lt;code>e(b)&lt;/code>; &lt;code>e(coef_map)&lt;/code> gives the cell of each one. An aggregate that needs an unavailable cell is unavailable unless &lt;code>estat&lt;/code> is given &lt;code>narm&lt;/code>, in which case it describes the restricted target and records the excluded cells.&lt;/p>
&lt;h3 id="covariates-missing-at-a-reference-date">Covariates missing at a reference date&lt;/h3>
&lt;p>Under &lt;code>missingreference(exclude)&lt;/code>, chained cohort fits post:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Result&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(missing_reference)&lt;/code>&lt;/td>
&lt;td>&lt;code>exclude&lt;/code> or &lt;code>error&lt;/code>; not posted with the preset.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_status)&lt;/code>&lt;/td>
&lt;td>&lt;code>restricted&lt;/code> (some cohort comparisons were restricted), &lt;code>auxiliary_unavailable&lt;/code> (only pretrend comparisons became unavailable) or &lt;code>unrestricted&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_eligibility)&lt;/code>&lt;/td>
&lt;td>Restricted fits: one row per target cohort (rows &lt;code>g3&lt;/code>, &lt;code>g4&lt;/code>, &amp;hellip;) with columns &lt;code>cohort&lt;/code>, &lt;code>reference_date&lt;/code>, &lt;code>n_treated&lt;/code>, &lt;code>n_treated_eligible&lt;/code>, &lt;code>n_treated_excluded&lt;/code>, &lt;code>n_never_treated_excluded&lt;/code>, &lt;code>n_other_cohort_excluded&lt;/code> and &lt;code>restricted&lt;/code>. The excluded counts are taken across all supplied units at the cohort&amp;rsquo;s reference date, including units outside the cohort&amp;rsquo;s comparison groups.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_contexts)&lt;/code>&lt;/td>
&lt;td>Restricted fits: one row per restricted reference date, columns &lt;code>reference_date&lt;/code> and &lt;code>n_excluded&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_aux_unavailable)&lt;/code>&lt;/td>
&lt;td>One row per unavailable pretrend comparison, columns &lt;code>cohort&lt;/code>, &lt;code>s&lt;/code> and &lt;code>t&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_variables)&lt;/code>&lt;/td>
&lt;td>The covariates whose reference values were checked.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(reference_restricted)&lt;/code>&lt;/td>
&lt;td>The restricted cohorts.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The record is saved by &lt;code>saving()&lt;/code> and restored by &lt;code>cdid_load&lt;/code>, and &lt;code>estat&lt;/code> aggregations use the restricted cohort masses.&lt;/p>
&lt;h2 id="aggregated-results">Aggregated results&lt;/h2>
&lt;p>&lt;code>estat simple|group|dynamic|calendar&lt;/code> replaces &lt;code>e()&lt;/code> with the aggregation. The four types average the post-treatment cells overall, by cohort, by time since adoption and by calendar date; &lt;code>estat dynamic&lt;/code> also reports the pretreatment event times, and each type reports an overall estimate. Cohort shares are computed over the study population.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(N_cells)&lt;/code>&lt;/td>
&lt;td>number of group-time cells of the fit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_targets)&lt;/code>&lt;/td>
&lt;td>number of aggregation bins&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_posted)&lt;/code>&lt;/td>
&lt;td>number of estimates in &lt;code>e(b)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(bstrap)&lt;/code>&lt;/td>
&lt;td>bootstrap flag used&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cband)&lt;/code>&lt;/td>
&lt;td>band flag used&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_att)&lt;/code>&lt;/td>
&lt;td>overall estimate&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_se)&lt;/code>&lt;/td>
&lt;td>its reported standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_analytic_se)&lt;/code>&lt;/td>
&lt;td>its analytical standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_ci_low)&lt;/code>&lt;/td>
&lt;td>lower limit of its pointwise interval&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_ci_high)&lt;/code>&lt;/td>
&lt;td>upper limit of its pointwise interval&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_n_draws)&lt;/code>&lt;/td>
&lt;td>bootstrap draws for the overall estimate&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_draws_used)&lt;/code>&lt;/td>
&lt;td>1 if bootstrap draws were used for it&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(n_draws)&lt;/code>&lt;/td>
&lt;td>bootstrap draws for the bins&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(draws_used)&lt;/code>&lt;/td>
&lt;td>1 if bootstrap draws were used for the bins&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(min_e)&lt;/code>&lt;/td>
&lt;td>value of mine()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(max_e)&lt;/code>&lt;/td>
&lt;td>value of maxe()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(balance_e)&lt;/code>&lt;/td>
&lt;td>value of balancee()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(na_rm)&lt;/code>&lt;/td>
&lt;td>1 with narm&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(title)&lt;/code>&lt;/td>
&lt;td>title of the fit, followed by the aggregation type&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(estat_cmdline)&lt;/code>&lt;/td>
&lt;td>the estat command as typed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(agg_type)&lt;/code>&lt;/td>
&lt;td>simple, group, dynamic, or calendar&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(subcmd)&lt;/code>&lt;/td>
&lt;td>the estat subcommand&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(result_kind)&lt;/code>&lt;/td>
&lt;td>aggregation&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_status)&lt;/code>&lt;/td>
&lt;td>status of the overall estimate&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_reason)&lt;/code>&lt;/td>
&lt;td>why it is unavailable, when it is&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_inference_status)&lt;/code>&lt;/td>
&lt;td>status of its inference&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(overall_inference_kind)&lt;/code>&lt;/td>
&lt;td>type of its standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(band_family)&lt;/code>&lt;/td>
&lt;td>type of band&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(target_definition)&lt;/code>&lt;/td>
&lt;td>definition of the aggregated targets&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(weight_reduction)&lt;/code>&lt;/td>
&lt;td>how unit weights were reduced&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(weight_source)&lt;/code>&lt;/td>
&lt;td>source of the weights&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selector_warning)&lt;/code>&lt;/td>
&lt;td>note about mine(), maxe(), or balancee(), when any&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>In chained mode, estat also posts the results of cdid that describe the data, the inference and the posting (&lt;code>e(N)&lt;/code>, &lt;code>e(N_full)&lt;/code>, &lt;code>e(clustered)&lt;/code>, &lt;code>e(N_clust)&lt;/code>, &lt;code>e(level)&lt;/code>, &lt;code>e(alpha)&lt;/code>, &lt;code>e(critical_value)&lt;/code>, e(wald_*), &lt;code>e(vce)&lt;/code>, &lt;code>e(band)&lt;/code>, &lt;code>e(rng)&lt;/code>, &lt;code>e(b)&lt;/code>, &lt;code>e(V)&lt;/code>, &lt;code>e(se)&lt;/code>, &lt;code>e(ci)&lt;/code>, &lt;code>e(coef_map)&lt;/code>, &amp;hellip;) and the settings macros of the fit, except &lt;code>e(anticipation)&lt;/code>, &lt;code>e(inactive_options)&lt;/code>, &lt;code>e(missing_reference)&lt;/code>, &lt;code>e(reference_status)&lt;/code>, and &lt;code>e(nuisance)&lt;/code>; &lt;code>e(cmdline)&lt;/code> and &lt;code>e(sample)&lt;/code> are those of the fit. In ordinary mode, estat posts the results listed for ordinary fits in help cdid, except &lt;code>e(inactive_options)&lt;/code>, &lt;code>e(V_did)&lt;/code>, and &lt;code>e(V_did_asymptotic)&lt;/code>, and adds &lt;code>e(estat_cmdline)&lt;/code>; &lt;code>e(N_targets)&lt;/code> and &lt;code>e(N_posted)&lt;/code> count the bins and the overall estimate, which is the last element of &lt;code>e(b)&lt;/code>. The overall-effect scalars, &lt;code>e(agg_type)&lt;/code>, and &lt;code>e(subcmd)&lt;/code> are posted in chained mode only.&lt;/p>
&lt;h2 id="uncertainty">Uncertainty&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Result&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(V)&lt;/code>&lt;/td>
&lt;td>Analytical covariance of &lt;code>e(b)&lt;/code>, from the unit influence functions.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V_asymptotic)&lt;/code>&lt;/td>
&lt;td>&lt;code>e(N_full)&lt;/code> times &lt;code>e(V)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(analytic_se)&lt;/code>&lt;/td>
&lt;td>Square roots of the diagonal of &lt;code>e(V)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se)&lt;/code>&lt;/td>
&lt;td>Reported standard errors: analytical with &lt;code>bstrap(0)&lt;/code>, from the multiplier bootstrap (interquartile range of the draws) with &lt;code>bstrap(1)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ci)&lt;/code>&lt;/td>
&lt;td>Reported intervals: simultaneous bands with &lt;code>cband(1)&lt;/code>, pointwise intervals otherwise.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ci_pointwise)&lt;/code>&lt;/td>
&lt;td>Pointwise intervals.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(critical_value)&lt;/code>&lt;/td>
&lt;td>Critical value of the reported intervals or bands.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Because the reported standard errors can come from the bootstrap, &lt;code>sqrt(e(V)[k,k])&lt;/code> need not equal &lt;code>e(se)[1,k]&lt;/code>. The influence functions include the estimation of every fitted model (treatment, outcome, observation and imputation models, cohort shares). With &lt;code>cluster()&lt;/code>, scores are summed within clusters. The multiplier bootstrap draws one Rademacher sign per cluster from Stata&amp;rsquo;s random-number stream.&lt;/p>
&lt;h3 id="point-estimates-only">Point estimates only&lt;/h3>
&lt;p>With &lt;code>noinffunc&lt;/code>, &lt;code>e(V)&lt;/code> and &lt;code>e(V_asymptotic)&lt;/code> are not posted and &lt;code>e(point_only)&lt;/code> is 1. With &lt;code>posting(matrix)&lt;/code> and at least one available cell, &lt;code>e(b)&lt;/code> is posted, &lt;code>e(se)&lt;/code>, &lt;code>e(analytic_se)&lt;/code>, &lt;code>e(ci)&lt;/code> and &lt;code>e(ci_pointwise)&lt;/code> are posted with missing entries, and &lt;code>e(properties)&lt;/code> is &lt;code>b&lt;/code>; with &lt;code>posting(state)&lt;/code>, no matrix is posted and &lt;code>e(properties)&lt;/code> is empty. &lt;code>estat&lt;/code> is refused.&lt;/p>
&lt;h2 id="pretrend-tests">Pretrend tests&lt;/h2>
&lt;p>The joint Wald test of the pretreatment cells is stored in &lt;code>e(wald_statistic)&lt;/code>, &lt;code>e(wald_df)&lt;/code> and &lt;code>e(wald_p)&lt;/code>, with &lt;code>e(wald_status)&lt;/code> and, when it is not computed, &lt;code>e(wald_reason)&lt;/code>. It uses the analytical covariance; failure to reject does not establish parallel trends.&lt;/p>
&lt;p>&lt;code>cdid_pretest&lt;/code> returns the conditional test in &lt;code>r()&lt;/code>:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(CvM)&lt;/code>&lt;/td>
&lt;td>Cramér-von Mises statistic&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(CvMcval)&lt;/code>&lt;/td>
&lt;td>bootstrap critical value at level()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(CvMpval)&lt;/code>&lt;/td>
&lt;td>bootstrap p-value (share of draws strictly above &lt;code>r(CvM)&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N)&lt;/code>&lt;/td>
&lt;td>number of units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(M)&lt;/code>&lt;/td>
&lt;td>number of evaluation points (one per unit in chained mode)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(K)&lt;/code>&lt;/td>
&lt;td>number of pretreatment cells tested&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(C)&lt;/code>&lt;/td>
&lt;td>number of clusters&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(B)&lt;/code>&lt;/td>
&lt;td>number of bootstrap draws&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(alpha)&lt;/code>&lt;/td>
&lt;td>1 - level/100&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_input)&lt;/code>&lt;/td>
&lt;td>observations supplied&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_requested)&lt;/code>&lt;/td>
&lt;td>observations requested&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_rows)&lt;/code>&lt;/td>
&lt;td>rows used&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_distinct)&lt;/code>&lt;/td>
&lt;td>distinct units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(multipliers_used)&lt;/code>&lt;/td>
&lt;td>1 if bootstrap multipliers were drawn or supplied&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(bstrap_requested)&lt;/code>&lt;/td>
&lt;td>value of bstrap()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(cband_requested)&lt;/code>&lt;/td>
&lt;td>value of cband()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_callbacks)&lt;/code>&lt;/td>
&lt;td>number of callback calls, with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(allowunbalanced_supplied)&lt;/code>&lt;/td>
&lt;td>1 if allowunbalanced() was specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(rcs_dr_corrected_if)&lt;/code>&lt;/td>
&lt;td>1 when the ordinary doubly robust test with repeated cross-sections uses the corrected influence function&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(formula_defaulted)&lt;/code>&lt;/td>
&lt;td>1 when the ordinary test used the intercept-only model by default&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(id_defaulted)&lt;/code>&lt;/td>
&lt;td>1 when repeated cross-sections used observation identifiers by default&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(status)&lt;/code>&lt;/td>
&lt;td>available, unavailable, or not_applicable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(reason)&lt;/code>&lt;/td>
&lt;td>reason, when the test is not available&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(mode)&lt;/code>&lt;/td>
&lt;td>chained or ordinary&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(method)&lt;/code>&lt;/td>
&lt;td>treatment adjustment&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(formula)&lt;/code>&lt;/td>
&lt;td>covariates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(X_columns)&lt;/code>&lt;/td>
&lt;td>columns of the treatment design&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(Z_columns)&lt;/code>&lt;/td>
&lt;td>columns of the evaluation grid&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(outcome_pooling)&lt;/code>&lt;/td>
&lt;td>outcome-regression pooling, when active&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(clustervars)&lt;/code>&lt;/td>
&lt;td>cluster variable, with cluster()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(callback)&lt;/code>&lt;/td>
&lt;td>callback(), with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(payload)&lt;/code>&lt;/td>
&lt;td>payload(), with method(custom)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(allowunbalanced_requested)&lt;/code>&lt;/td>
&lt;td>value of allowunbalanced(), when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(inactive_options)&lt;/code>&lt;/td>
&lt;td>accepted options that have no effect in ordinary mode, specified or not&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(posting)&lt;/code>&lt;/td>
&lt;td>matrix or state&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(state_token)&lt;/code>&lt;/td>
&lt;td>name of the store() object, with store()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(rng)&lt;/code>&lt;/td>
&lt;td>source of the multipliers, in words&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(description)&lt;/code>&lt;/td>
&lt;td>construction of the test, in words&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(grid_rule)&lt;/code>&lt;/td>
&lt;td>evaluation grid, in words&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(influence_function)&lt;/code>&lt;/td>
&lt;td>influence function used, in words&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Matrices&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(CvMb)&lt;/code>&lt;/td>
&lt;td>B x 1 bootstrap draws of the statistic&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(family)&lt;/code>&lt;/td>
&lt;td>tested pretreatment cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(grid)&lt;/code>&lt;/td>
&lt;td>evaluation grid: first_grid_row and multiplicity&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>When the test is unavailable or not applicable, the statistics are missing and &lt;code>r(CvMb)&lt;/code> is not returned. cdid_pretest_load returns the same results, except &lt;code>r(callback)&lt;/code>, &lt;code>r(payload)&lt;/code>, &lt;code>r(n_callbacks)&lt;/code>, and &lt;code>r(inactive_options)&lt;/code>, and adds &lt;code>r(state_file)&lt;/code>.&lt;/p>
&lt;h2 id="results-of-cdid-with-dvar">Results of cdid with dvar()&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> with &lt;code>dvar()&lt;/code> stores the following in &lt;code>e()&lt;/code>; &lt;code>estat&lt;/code> does not apply.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(N)&lt;/code>&lt;/td>
&lt;td>number of units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(T)&lt;/code>&lt;/td>
&lt;td>number of dates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_clust)&lt;/code>&lt;/td>
&lt;td>number of clusters, with cluster()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(att)&lt;/code>&lt;/td>
&lt;td>switcher-weighted average effect&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se_att)&lt;/code>&lt;/td>
&lt;td>its reported standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se_att_analytic)&lt;/code>&lt;/td>
&lt;td>its analytical standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(se_att_bootstrap)&lt;/code>&lt;/td>
&lt;td>its bootstrap standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(n_switchers)&lt;/code>&lt;/td>
&lt;td>number of switchers in the requested cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(N_missing)&lt;/code>&lt;/td>
&lt;td>number of missing outcomes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(critical_value)&lt;/code>&lt;/td>
&lt;td>critical value of the reported intervals or band&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(level)&lt;/code>&lt;/td>
&lt;td>confidence level&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(alpha)&lt;/code>&lt;/td>
&lt;td>1 - &lt;code>e(level)&lt;/code>/100&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(biters)&lt;/code>&lt;/td>
&lt;td>bootstrap draws requested (biters())&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(draws)&lt;/code>&lt;/td>
&lt;td>1 if bootstrap draws were used&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(cmd)&lt;/code>&lt;/td>
&lt;td>cdid&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cmdline)&lt;/code>&lt;/td>
&lt;td>command as typed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(title)&lt;/code>&lt;/td>
&lt;td>title of the output&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(design)&lt;/code>&lt;/td>
&lt;td>static&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(mode)&lt;/code>&lt;/td>
&lt;td>chained&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(depvar)&lt;/code>&lt;/td>
&lt;td>outcome&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(ivar)&lt;/code>&lt;/td>
&lt;td>unit identifier&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(time)&lt;/code>&lt;/td>
&lt;td>date variable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(dvar)&lt;/code>&lt;/td>
&lt;td>treatment status variable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(covariates)&lt;/code>&lt;/td>
&lt;td>covariates&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(method)&lt;/code>&lt;/td>
&lt;td>treatment adjustment&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(switchers)&lt;/code>&lt;/td>
&lt;td>both, entry, or exit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(switchtimes)&lt;/code>&lt;/td>
&lt;td>dates of switchtimes(), when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(outcome_pooling)&lt;/code>&lt;/td>
&lt;td>outcome-regression pooling&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(gmm_weighting)&lt;/code>&lt;/td>
&lt;td>GMM weighting, with missing outcomes or selection()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection)&lt;/code>&lt;/td>
&lt;td>assumption about missing outcomes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_est_method)&lt;/code>&lt;/td>
&lt;td>correction for missing outcomes, when it applies&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_model)&lt;/code>&lt;/td>
&lt;td>observation model, when it applies&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_pooling)&lt;/code>&lt;/td>
&lt;td>observation-model pooling, when it applies&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_universe)&lt;/code>&lt;/td>
&lt;td>units that fit the observation model, when it applies&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_rho)&lt;/code>&lt;/td>
&lt;td>density-ratio variable, when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_justification)&lt;/code>&lt;/td>
&lt;td>text of seljustification(), when specified&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(selection_covariates)&lt;/code>&lt;/td>
&lt;td>observation-model covariates, when they apply&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(imputation_pooling)&lt;/code>&lt;/td>
&lt;td>imputation pooling, when it applies&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(imputation_scale)&lt;/code>&lt;/td>
&lt;td>imputation scaling, when it applies&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(vce)&lt;/code>&lt;/td>
&lt;td>analytic, bootstrap, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(vcetype)&lt;/code>&lt;/td>
&lt;td>Bootstrap, with the multiplier bootstrap&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(band)&lt;/code>&lt;/td>
&lt;td>pointwise or simultaneous&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(band_status)&lt;/code>&lt;/td>
&lt;td>ok, not_requested, unavailable_target_cell, or unavailable_degenerate_family&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(clustvar)&lt;/code>&lt;/td>
&lt;td>cluster variable, with cluster()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(nuisance)&lt;/code>&lt;/td>
&lt;td>availability of the reports kept, with keepnuisance&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(state_token)&lt;/code>&lt;/td>
&lt;td>reference to the kept reports, with keepnuisance&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(estat_cmd)&lt;/code>&lt;/td>
&lt;td>cdid_estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(properties)&lt;/code>&lt;/td>
&lt;td>b V, or b with noinffunc&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Matrices&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(b)&lt;/code>&lt;/td>
&lt;td>estimable cell effects, named direction:tdate (for example &lt;code>_b[entry:t2003]&lt;/code>)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(V)&lt;/code>&lt;/td>
&lt;td>analytical covariance of &lt;code>e(b)&lt;/code>, unless noinffunc&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>e(cells)&lt;/code>&lt;/td>
&lt;td>one row per requested cell; see the column definitions below&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Functions&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>e(sample)&lt;/code>&lt;/td>
&lt;td>marks the observations used&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>e(b)&lt;/code> and &lt;code>e(V)&lt;/code> are not posted when no requested cell is available. The columns of &lt;code>e(cells)&lt;/code> are: time, the date t; tprev, the preceding study date; d, the treatment status before the switch (0 for entries, 1 for exits); sign, the sign applied to the switcher-stayer contrast (1 for entries, -1 for exits); available, 1 if the cell is estimated; switchers and stayers, the numbers of units; att, the cell effect; theta, the switcher-stayer contrast before the sign is applied; se, lower and upper, the reported standard error and interval limits; analytic_se and bootstrap_se; and status, 0 when the cell is available, 1 with no switchers, 2 with no stayers, 3 when the observed dates of the switchers do not connect the preceding date and t, and 4 when those of the stayers do not.&lt;/p>
&lt;h2 id="chain-and-model-reports">Chain and model reports&lt;/h2>
&lt;p>&lt;code>cdid_chain&lt;/code> returns:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(n_cells)&lt;/code>&lt;/td>
&lt;td>number of cells reported&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_available)&lt;/code>&lt;/td>
&lt;td>number of available cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_chained)&lt;/code>&lt;/td>
&lt;td>number of available cells that require chaining&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_moments)&lt;/code>&lt;/td>
&lt;td>number of comparisons used by GMM&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(overid_df)&lt;/code>&lt;/td>
&lt;td>number of overidentifying restrictions&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(kind)&lt;/code>&lt;/td>
&lt;td>crosspair or samepair&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>cdid_nuisance&lt;/code> returns the following; the block results refer to the selected block:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(N)&lt;/code>&lt;/td>
&lt;td>number of units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_blocks)&lt;/code>&lt;/td>
&lt;td>number of blocks&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_units)&lt;/code>&lt;/td>
&lt;td>units in the selected block&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_fitting_rows)&lt;/code>&lt;/td>
&lt;td>fitting rows of the selected block&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(n_comparisons)&lt;/code>&lt;/td>
&lt;td>comparisons that use the selected block&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(component)&lt;/code>&lt;/td>
&lt;td>component displayed&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(status)&lt;/code>&lt;/td>
&lt;td>available, not_applicable, not_captured, or unavailable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(reason)&lt;/code>&lt;/td>
&lt;td>why a component is not available&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(status_component)&lt;/code>&lt;/td>
&lt;td>status of each component, for example &lt;code>r(status_selection)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(method)&lt;/code>&lt;/td>
&lt;td>treatment adjustment&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(selmethod)&lt;/code>&lt;/td>
&lt;td>correction for missing outcomes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(block)&lt;/code>&lt;/td>
&lt;td>identifier of the selected block&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(label)&lt;/code>&lt;/td>
&lt;td>label of the selected block&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(equation)&lt;/code>&lt;/td>
&lt;td>equation of the selected block&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(terms)&lt;/code>&lt;/td>
&lt;td>labels of the coefficients of the selected block&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(kept_slopes)&lt;/code>&lt;/td>
&lt;td>slopes kept, after the preset&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(aliased_slopes)&lt;/code>&lt;/td>
&lt;td>slopes dropped as exact aliases, after the preset&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(roster_terms)&lt;/code>&lt;/td>
&lt;td>labels of &lt;code>r(roster)&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Matrices&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(blocks)&lt;/code>&lt;/td>
&lt;td>one row per block: parameters, fitting rows, units or weights, comparisons, and related counts&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(table)&lt;/code>&lt;/td>
&lt;td>coefficients of the selected block, with standard errors, z statistics, p-values, and 95% confidence limits&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(roster)&lt;/code>&lt;/td>
&lt;td>roster probabilities, after the preset with seluniverse(A) or seluniverse(B)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="diagnostics">Diagnostics&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scalars&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(N_units)&lt;/code>&lt;/td>
&lt;td>number of units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_treated)&lt;/code>&lt;/td>
&lt;td>treated units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_never_treated)&lt;/code>&lt;/td>
&lt;td>never-treated units&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_unknown_cohort)&lt;/code>&lt;/td>
&lt;td>units with unknown cohort&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_with_rows)&lt;/code>&lt;/td>
&lt;td>units with data rows&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_frame_only)&lt;/code>&lt;/td>
&lt;td>units supplied only through frame()&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_with_outcome)&lt;/code>&lt;/td>
&lt;td>units with at least one observed outcome&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_with_two_outcomes)&lt;/code>&lt;/td>
&lt;td>units with at least two observed outcomes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_cluster_ids)&lt;/code>&lt;/td>
&lt;td>distinct cluster identifiers retained from the fit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_clust)&lt;/code>&lt;/td>
&lt;td>clusters used for cell inference, missing when unclustered&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(weight_sum)&lt;/code>&lt;/td>
&lt;td>sum of unit weights&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(weight_min)&lt;/code>&lt;/td>
&lt;td>smallest unit weight&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(weight_max)&lt;/code>&lt;/td>
&lt;td>largest unit weight&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_cells)&lt;/code>&lt;/td>
&lt;td>number of cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_post)&lt;/code>&lt;/td>
&lt;td>post-treatment cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_pre)&lt;/code>&lt;/td>
&lt;td>pretreatment cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_reference)&lt;/code>&lt;/td>
&lt;td>reference cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_available)&lt;/code>&lt;/td>
&lt;td>available cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_unavailable)&lt;/code>&lt;/td>
&lt;td>unavailable cells&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_with_se)&lt;/code>&lt;/td>
&lt;td>cells with a standard error&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(B_requested)&lt;/code>&lt;/td>
&lt;td>number of multiplier draws requested&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(wald_statistic)&lt;/code>&lt;/td>
&lt;td>pretrend Wald statistic&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(wald_df)&lt;/code>&lt;/td>
&lt;td>its degrees of freedom&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(wald_p)&lt;/code>&lt;/td>
&lt;td>its p-value&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_aggregates)&lt;/code>&lt;/td>
&lt;td>aggregation bins, after estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(N_aggregates_available)&lt;/code>&lt;/td>
&lt;td>available bins, after estat&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Macros&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(mode)&lt;/code>&lt;/td>
&lt;td>chained or ordinary&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(result_kind)&lt;/code>&lt;/td>
&lt;td>cells or aggregation&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(agg_type)&lt;/code>&lt;/td>
&lt;td>aggregation type, after estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(method)&lt;/code>&lt;/td>
&lt;td>treatment adjustment&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(control_group)&lt;/code>&lt;/td>
&lt;td>comparison group&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(base_period)&lt;/code>&lt;/td>
&lt;td>base period&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(pt_assumption)&lt;/code>&lt;/td>
&lt;td>parallel trends assumption&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(gmm_weighting)&lt;/code>&lt;/td>
&lt;td>GMM weighting&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(selection)&lt;/code>&lt;/td>
&lt;td>assumption about missing outcomes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(wald_status)&lt;/code>&lt;/td>
&lt;td>status of the pretrend Wald test&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(inference_status)&lt;/code>&lt;/td>
&lt;td>status of the inference&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(band)&lt;/code>&lt;/td>
&lt;td>intervals for the cells: pointwise, simultaneous, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(vce)&lt;/code>&lt;/td>
&lt;td>standard errors for the cells: analytic, bootstrap, or none&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(clustvar)&lt;/code>&lt;/td>
&lt;td>cluster variable retained from the ordinary fit&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(rng)&lt;/code>&lt;/td>
&lt;td>source of multiplier draws, in chained mode&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(inactive_options)&lt;/code>&lt;/td>
&lt;td>inactive options in the chained specification&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(wald_reason)&lt;/code>&lt;/td>
&lt;td>cells used by the test or why it was unavailable&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(overall_status)&lt;/code>&lt;/td>
&lt;td>availability of the overall summary, after estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(overall_reason)&lt;/code>&lt;/td>
&lt;td>reason for an unavailable overall summary, after estat&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(cells_matrix)&lt;/code>&lt;/td>
&lt;td>note posted instead of &lt;code>r(cells)&lt;/code> when the table exceeds c(max_matdim); use cdid_export&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(aggregate_matrix)&lt;/code>&lt;/td>
&lt;td>the same for &lt;code>r(aggregate)&lt;/code>, after estat&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Matrices&lt;/th>
&lt;th>Content&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>r(cells)&lt;/code>&lt;/td>
&lt;td>cells: cohort, date, role, availability, estimate, standard error, and bounds&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>r(aggregate)&lt;/code>&lt;/td>
&lt;td>aggregation bins, after estat&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>cdid_diagnostics returns every displayed quantity in r(); the lists above are the main results. A missing numeric quantity is accompanied by &lt;code>r(name_status)&lt;/code>, which explains why. The matrices are returned only when they fit within c(max_matdim).&lt;/p>
&lt;h2 id="saving-and-exporting">Saving and exporting&lt;/h2>
&lt;p>&lt;code>saving()&lt;/code> writes the complete results of &lt;code>cdid&lt;/code> with &lt;code>gvar()&lt;/code>, of &lt;code>estat&lt;/code> after such a fit, or of &lt;code>cdid_pretest&lt;/code> (it is not available with &lt;code>dvar()&lt;/code>); &lt;code>cdid_load&lt;/code> and &lt;code>cdid_pretest_load&lt;/code> restore them, with &lt;code>e(state_file)&lt;/code> or &lt;code>r(state_file)&lt;/code> naming the file. &lt;code>cdid_export&lt;/code> writes the cells, the aggregation, the units, the influence functions or a summary as Stata datasets; see &lt;code>help cdid_export&lt;/code> for their variables.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 19 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/options/">Options reference&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/troubleshooting/">Diagnose errors and unavailable results&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Sampling information for the observation model</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/sampling-information/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/sampling-information/</guid><description>&lt;p>Observation weighting under &lt;code>selection(conditional_mtar) selmethod(ipw)&lt;/code> fits an observation model on a set of units chosen with &lt;code>seluniverse()&lt;/code>. This page explains the choice of that set and the use of known transport weights. Changing the set changes the probability being modeled, not the target population, and not only the number of observations in the likelihood.&lt;/p>
&lt;h2 id="1-the-three-fitting-universes">1. The three fitting universes&lt;/h2>
&lt;p>The nested sets are $A \subseteq B \subseteq F$: $F$ is the study population, $B$ has at least one observed outcome and $A$ has at least two. A unit observed on a particular pair belongs to all three. Singletons and units never observed remain in the target population even when the observation logit is fitted on a subset.&lt;/p>
&lt;p>Only &lt;code>selmethod(ipw) selmodel(pair_logit)&lt;/code> offers &lt;code>seluniverse(B)&lt;/code> and &lt;code>seluniverse(A)&lt;/code>. Independent-period logits, pure imputation and the augmented correction require &lt;code>F&lt;/code>; imputation and the augmented correction also do not allow &lt;code>selrho()&lt;/code>.&lt;/p>
&lt;h2 id="2-what-a-restricted-fitting-set-assumes">2. What a restricted fitting set assumes&lt;/h2>
&lt;p>Let $W$ be a set of covariates sufficient for the assumption on missing outcomes and let $U$ be $B$ or $A$. Define&lt;/p>
&lt;p>$$q_U(e,W,G)=P(S_e=1\mid W,G,U),\qquad \pi_U(G)=P(U\mid G).$$&lt;/p>
&lt;p>If no &lt;code>selrho()&lt;/code> column is supplied, the required &lt;code>seljustification()&lt;/code> states the assumption that $U$ and the cohort have the same covariate distribution in the weighted population. With known transport, the column is the fixed, known, normalized density ratio&lt;/p>
&lt;p>$$\rho_U(W,G)=\frac{f_P(W\mid G,U)}{f_P(W\mid G)},$$&lt;/p>
&lt;p>with the &lt;strong>fitting-set density in the numerator&lt;/strong>. Since $S_e=1$ implies membership in $U$,&lt;/p>
&lt;p>$$P(S_e=1\mid W,G)=\pi_U(G),\rho_U(W,G),q_U(e,W,G).$$&lt;/p>
&lt;p>Within a cohort, the observation adjustment is proportional to the inverse of this probability. Up to cohort-rate normalizations, its unit factor is&lt;/p>
&lt;p>$$w_i S_{i,e}\big/{\rho_U(W_i,G_i)\max(\hat q_U(e,W_i,G_i),10^{-6})}.$$&lt;/p>
&lt;p>The ratio divides the weights. &lt;code>cdid&lt;/code> neither estimates nor renormalizes it. It must be positive and finite on the fitting set; estimated or unnormalized ratios are not supported. A valid ratio also requires the density of the fitting set to be positive wherever the target population needs it. A logit that fits well establishes none of these assumptions.&lt;/p>
&lt;p>For example, let a cohort have population shares $(0.5,0.5)$ at binary $X=(0,1)$, fitting-set mass $P(A\mid G)=0.4$, fitting-set shares $(0.25,0.75)$, ratios $(0.5,1.5)$ and $q_A=0.5$ in both strata. The population pair probabilities are $(0.1,0.3)$. Their inverse factors $(10,10/3)$ restore equal population shares. Assuming a ratio of one would not.&lt;/p>
&lt;h2 id="3-supported-settings">3. Supported settings&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Setting&lt;/th>
&lt;th>Observation model&lt;/th>
&lt;th>Requirement&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>seluniverse(F)&lt;/code>&lt;/td>
&lt;td>&lt;code>pair_logit&lt;/code> or &lt;code>independent_period_logit&lt;/code>&lt;/td>
&lt;td>Omit &lt;code>selrho()&lt;/code>; justification is optional.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>seluniverse(B)&lt;/code> or &lt;code>seluniverse(A)&lt;/code>&lt;/td>
&lt;td>&lt;code>selmethod(ipw) selmodel(pair_logit)&lt;/code> only&lt;/td>
&lt;td>Nonempty &lt;code>seljustification()&lt;/code>; without &lt;code>selrho()&lt;/code>, the covariate distribution of the set is assumed representative.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Restricted universe with &lt;code>selrho(varname)&lt;/code>&lt;/td>
&lt;td>&lt;code>selmethod(ipw) selmodel(pair_logit)&lt;/code> only&lt;/td>
&lt;td>Known positive normalized ratio as defined above, and &lt;code>seljustification()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>With covariates that are constant within units, the observation covariates and the ratio must be nonmissing on the fitting set. The other models used keep their own requirements on the covariates of the whole population. The identity above concerns covariates that are constant within units; it does not extend automatically to covariates that change over time.&lt;/p>
&lt;h2 id="4-example">4. Example&lt;/h2>
&lt;p>With the data of the hands-on do-file in memory, a pair logit fitted on $B$ is specified as:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y i.x_bin c.x_cont, ivar(id) time(period) gvar(first_treat) ///
selection(conditional_mtar) selmethod(ipw) ///
selmodel(pair_logit) seluniverse(B) ///
seljustification(&amp;quot;Substantively justified representative fitting set B&amp;quot;) ///
frame(cdid_pop) framecovars(x_bin x_cont) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;p>Use &lt;code>A&lt;/code> instead of &lt;code>B&lt;/code> only with a justification that applies to $A$. An analysis with known transport also supplies the known ratio through &lt;code>selrho()&lt;/code>; the simulated data contain no such ratio, and one should not be estimated or invented to run this example. A fit on a restricted set can still fail the checks of support, rank or convergence. Fitting on fewer observations implies neither faster computation nor smaller standard errors.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 10 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/observation-models/">Choose an observation model for missing outcomes&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Short pretreatment windows and cross-pair chaining</title><link>https://www.davidbenatia.com/tools/cdid/stata/examples/short-pretreatment-windows/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/examples/short-pretreatment-windows/</guid><description>&lt;p>Panels with staggered adoption often observe each unit only over a limited window around treatment: administrative registers that follow workers over fixed windows around an event, rotating household surveys, or longitudinal surveys that switch from annual to biennial waves. Without never-treated units, two-period comparisons with not-yet-treated controls run out of control cohorts at long horizons: by the time an early cohort $g$ reaches $g + 4$, the cohorts observed at its reference date $g - 1$ have already been treated, and the cohorts still untreated at $g + 4$ were not yet observed at $g - 1$. This page shows how chained estimation recovers these effects, how to inspect the control chains with &lt;code>cdid_chain&lt;/code>, and how to choose between &lt;code>ptassumption(post)&lt;/code> and &lt;code>ptassumption(ctrl)&lt;/code> and between &lt;code>gmmweighting(optimal)&lt;/code> and &lt;code>gmmweighting(within)&lt;/code>.&lt;/p>
&lt;h2 id="a-staggered-short-window-panel-without-never-treated-units">A staggered short-window panel without never-treated units&lt;/h2>
&lt;p>The panel covers 2001 to 2010 and six adoption cohorts, 2005 to 2010, of 100 units each, with no never-treated units. Each cohort $g$ is observed from $\max(2001, g - 4)$ to 2010. The unit effect is related to the cohort, and the effect is $1 + (t - g)$ from the adoption date onward, so that ATT(2005, 2009) is 5.&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261111
set obs 600
generate long id = _n
generate int G = 2005 + floor((id - 1) / 100)
generate double alpha = rnormal(0.5 * (G - 2005), 1.2)
generate int first = max(2001, G - 4)
expand 2010 - first + 1
bysort id: generate int period = first + _n - 1
generate double y = alpha + 0.4 * (period - 2001) + cond(period &amp;gt;= G, 1 + (period - G), 0) + rnormal()
&lt;/code>&lt;/pre>
&lt;p>For cohort 2005, the reference date is 2004. Only cohorts 2009 and 2010 are untreated in 2008, and only cohort 2010 in 2009, but cohort 2009 enters the panel in 2005 and cohort 2010 in 2006: neither is observed in 2004. No single comparison group spans 2004 to 2008 or 2004 to 2009.&lt;/p>
&lt;h2 id="within-unit-weighting-and-optimal-weighting">Within-unit weighting and optimal weighting&lt;/h2>
&lt;p>In this design all units of a cohort share the same dates, and neither fit adjusts for covariates or for missing outcomes. The first fit uses cross-pair links, control parallel trends and within-unit weighting; its point estimates equal the coefficients of stacked target-cohort regressions on the same clean-control samples (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/from-other-packages/#cohort-chained-did">Cohort-Chained DiD&lt;/a>). The second uses the weaker PT-post with the default optimal weighting.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y, ivar(id) time(period) gvar(G) controlgroup(notyettreated) baseperiod(universal) crosspair ptassumption(ctrl) gmmweighting(within) bstrap(0) cband(0)
estimates store within
estat dynamic, narm
cdid y, ivar(id) time(period) gvar(G) controlgroup(notyettreated) crosspair ptassumption(post) bstrap(0) cband(0)
cdid y, ivar(id) time(period) gvar(G) controlgroup(notyettreated) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;p>The within-weighted fit:&lt;/p>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 600
Method: doubly robust (dr) Number of cells = 60
Cross-pair comparisons; GMM weighting: within
Control group: not yet treated; base period: universal
------------------------------------------------------------------------------
Group Time Role ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
2005 2001 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2005 2002 pre -.3205567 .1873138 -.687685 .04657163
2005 2003 pre .04395606 .162133 -.2738187 .3617308
2005 2004 reference 0 0 0 0
2005 2005 post .8395668 .1596788 .5266021 1.152532
2005 2006 post 2.123606 .1619789 1.806133 2.441078
2005 2007 post 2.913114 .1614665 2.596646 3.229583
2005 2008 post 4.134776 .1826639 3.776762 4.492791
2005 2009 post 5.208695 .1974261 4.821746 5.595643
2005 2010 post . . . .
Unavailable: the cross-pair comparisons do not connect this cell to the reference date
2006 2001 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2006 2002 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2006 2003 pre -.2362628 .1981004 -.6245324 .1520069
2006 2004 pre -.1639655 .1674376 -.4921373 .1642062
2006 2005 reference 0 0 0 0
2006 2006 post 1.235331 .1558061 .9299563 1.540705
2006 2007 post 2.00499 .1643578 1.682855 2.327126
2006 2008 post 3.121677 .1921316 2.745106 3.498248
2006 2009 post 4.158905 .1891561 3.788166 4.529644
2006 2010 post . . . .
Unavailable: the cross-pair comparisons do not connect this cell to the reference date
2007 2001 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2007 2002 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2007 2003 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2007 2004 pre .2055044 .183633 -.1544095 .5654184
2007 2005 pre .2483647 .1643524 -.07376004 .5704895
2007 2006 reference 0 0 0 0
2007 2007 post 1.404148 .153659 1.102982 1.705314
2007 2008 post 2.273054 .1871435 1.906259 2.639849
2007 2009 post 3.357806 .1979437 2.969844 3.745769
2007 2010 post . . . .
Unavailable: the cross-pair comparisons do not connect this cell to the reference date
2008 2001 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2008 2002 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2008 2003 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2008 2004 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2008 2005 pre -.04116385 .1894952 -.4125676 .3302399
2008 2006 pre -.1185174 .1746093 -.4607454 .2237106
2008 2007 reference 0 0 0 0
2008 2008 post 1.300169 .1789554 .949423 1.650915
2008 2009 post 2.391802 .1939501 2.011667 2.771937
2008 2010 post . . . .
Unavailable: the cross-pair comparisons do not connect this cell to the reference date
2009 2001 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2009 2002 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2009 2003 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2009 2004 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2009 2005 pre . . . .
Unavailable: the cross-pair comparisons do not connect this pre-treatment cell to the
reference date
2009 2006 pre -.08856543 .2006478 -.4818279 .304697
2009 2007 pre .01184403 .2250112 -.4291699 .4528579
2009 2008 reference 0 0 0 0
2009 2009 post .9958624 .2013366 .60125 1.390475
2009 2010 post . . . .
Unavailable: the cross-pair comparisons do not connect this cell to the reference date
2010 2001 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2001 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2002 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2002 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2003 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2003 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2004 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2004 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2005 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2005 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2006 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2006 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2007 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2007 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2008 pre . . . .
Unavailable: no control cohort is untreated at date 2009, so the comparison of dates 2008 and
2009 has no controls; cohorts in the data: 2005, 2006, 2007, 2008, 2009, 2010
2010 2009 reference 0 0 0 0
2010 2010 post . . . .
Unavailable: the cross-pair comparisons do not connect this cell to the reference date
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
Reference cells are zero by construction.
Pretrend Wald test: not computed; some pre-treatment cells are unavailable, and the test is not
computed on a subset of them.
&lt;/code>&lt;/pre>
&lt;p>Its event study, over the available cells:&lt;/p>
&lt;pre>&lt;code class="language-text">Chained difference-in-differences Number of units = 600
Method: doubly robust (dr) Number of event times = 15
Cross-pair comparisons; GMM weighting: within
Control group: not yet treated; base period: universal
Aggregation: dynamic
Event-time selection: narm
------------------------------------------------------------------------------
Event time ATT Std. err. [95% conf. interval]
------------------------------------------------------------------------------
Overall 3.167956 .1054286 2.96132 3.374592
------------------------------------------------------------------------------
-9 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2010 at date 2001
(pre-treatment)
-8 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2009 at date 2001
(pre-treatment); cohort 2010 at date 2002 (pre-treatment)
-7 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2008 at date 2001
(pre-treatment); cohort 2009 at date 2002 (pre-treatment); cohort 2010 at date 2003
(pre-treatment)
-6 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2007 at date 2001
(pre-treatment); cohort 2008 at date 2002 (pre-treatment); cohort 2009 at date 2003
(pre-treatment); cohort 2010 at date 2004 (pre-treatment)
-5 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2006 at date 2001
(pre-treatment); cohort 2007 at date 2002 (pre-treatment); cohort 2008 at date 2003
(pre-treatment); cohort 2009 at date 2004 (pre-treatment); cohort 2010 at date 2005
(pre-treatment)
-4 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2005 at date 2001
(pre-treatment); cohort 2006 at date 2002 (pre-treatment); cohort 2007 at date 2003
(pre-treatment); cohort 2008 at date 2004 (pre-treatment); cohort 2009 at date 2005
(pre-treatment); cohort 2010 at date 2006 (pre-treatment)
-3 -.09620886 .08625618 -.2652679 .07285015
-2 .00433638 .08023198 -.1529154 .1615882
-1 0 0 0 0
0 1.155015 .07762391 1.002875 1.307156
1 2.198363 .09820502 2.005885 2.390841
2 3.130866 .1198263 2.896011 3.365721
3 4.146841 .1430075 3.866551 4.42713
4 5.208695 .1974261 4.821746 5.595643
5 . . . .
Unavailable: every cell of this aggregate is unavailable: cohort 2005 at date 2010
(post-treatment)
------------------------------------------------------------------------------
Std. err.: analytic; pointwise 95% intervals.
The overall summary uses a pointwise interval.
Pretrend Wald test: not computed; some pre-treatment cells are unavailable, and the test is not
computed on a subset of them.
&lt;/code>&lt;/pre>
&lt;p>The other two fits, not shown, report the same set of available cells. All three fits estimate the 15 post-treatment effects of cohorts 2005 to 2009, including ATT(2005, 2008) and ATT(2005, 2009). On contiguous windows like these, same-pair chaining already links the reference date to later dates through overlapping control cohorts, so &lt;code>crosspair&lt;/code> is not needed for availability. The effects at 2010 are unavailable because every unit is treated by 2010, which leaves no untreated comparison.&lt;/p>
&lt;h2 id="inspect-the-control-chain">Inspect the control chain&lt;/h2>
&lt;p>&lt;code>cdid_chain&lt;/code> shows how the effects of cohort 2005 are identified, including ATT(2005, 2009), which links 2004 to 2009 although no control cohort is observed at both dates:&lt;/p>
&lt;pre>&lt;code class="language-stata">estimates restore within
cdid_chain, cohort(2005)
&lt;/code>&lt;/pre>
&lt;pre>&lt;code class="language-text">Identification chains (cross-pair, ptassumption(ctrl), gmmweighting(within))
Comparisons used by GMM: 84 Overidentifying restrictions: 20
Cells: 6 (5 estimable, 2 chained without a direct comparison, 1 unavailable)
Group Time Role Chain ATT Std. err.
---------------------------------------------------------------
2005 2005 post direct .839566816 .159678826
witness: 2004-&amp;gt;2005 [g=2005] - 2004-&amp;gt;2005 [ctrl{2006}]
2005 2006 post direct 2.12360559 .161978876
witness: 2004-&amp;gt;2005 [g=2005] + 2005-&amp;gt;2006 [g=2005] - 2004-&amp;gt;2005 [ctrl{2006}] - 2005-&amp;gt;2006 [ctrl{2007}]
2005 2007 post direct 2.9131141 .161466526
witness: 2004-&amp;gt;2005 [g=2005] + 2005-&amp;gt;2006 [g=2005] + 2006-&amp;gt;2007 [g=2005] - 2004-&amp;gt;2005 [ctrl{2006}] - 2005-&amp;gt;2006 [ctrl{2007}] - 2006-&amp;gt;2007 [ctrl{2008}]
2005 2008 post chained 4.13477612 .182663873
witness: 2004-&amp;gt;2005 [g=2005] + 2005-&amp;gt;2006 [g=2005] + 2006-&amp;gt;2007 [g=2005] + 2007-&amp;gt;2008 [g=2005] - 2004-&amp;gt;2005 [ctrl{2006}] - 2005-&amp;gt;2006 [ctrl{2007}] - 2006-&amp;gt;2007 [ctrl{2008}] - 2007-&amp;gt;2008 [ctrl{2009}]
2005 2009 post chained 5.20869451 .197426141
witness: 2004-&amp;gt;2005 [g=2005] + 2005-&amp;gt;2006 [g=2005] + 2006-&amp;gt;2007 [g=2005] + 2007-&amp;gt;2008 [g=2005] + 2008-&amp;gt;2009 [g=2005] - 2004-&amp;gt;2005 [ctrl{2006}] - 2005-&amp;gt;2006 [ctrl{2007}] - 2006-&amp;gt;2007 [ctrl{2008}] - 2007-&amp;gt;2008 [ctrl{2009}] - 2008-&amp;gt;2009 [ctrl{2010}]
2005 2010 post unavailable . .
the cross-pair comparisons do not connect this cell to the reference date
&lt;/code>&lt;/pre>
&lt;p>ATT(2005, 2005) is identified directly by control cohorts observed in both 2004 and 2005; ATT(2005, 2008) and ATT(2005, 2009) require chaining, and the witness path shows one combination of control changes that links the dates. &lt;code>cdid_chain, weights&lt;/code> lists the GMM weight of every comparison.&lt;/p>
&lt;h2 id="practical-recommendations">Practical recommendations&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>Keep irregular waves.&lt;/strong> &lt;code>cdid&lt;/code> chains over the stored study dates, so a switch from annual to biennial waves does not require dropping dates.&lt;/li>
&lt;li>&lt;strong>Keep unit identifiers.&lt;/strong> When attrition is related to persistent outcome levels, cohort fixed-effects regressions mix changes in composition with treatment effects, while within-unit differencing removes the persistent levels. The representativeness of the changes and parallel trends are still required.&lt;/li>
&lt;li>&lt;strong>Choose the assumption and the weighting.&lt;/strong> &lt;code>gmmweighting(within) ptassumption(ctrl)&lt;/code> reproduces the stacked regressions. &lt;code>ptassumption(post)&lt;/code> with the default &lt;code>gmmweighting(optimal)&lt;/code> avoids the PT-ctrl restriction before the reference date, whose violation by a control cohort would bias the post-treatment estimates, and estimates the covariance of the comparisons from the data.&lt;/li>
&lt;li>&lt;strong>Adjust when needed.&lt;/strong> Covariates, sampling weights that vary over time (&lt;code>fixweights()&lt;/code>), and covariate-dependent attrition (&lt;code>selection(conditional_mtar)&lt;/code> with any &lt;code>selmethod()&lt;/code>) are supported with &lt;code>crosspair&lt;/code>; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining&lt;/a>.&lt;/li>
&lt;/ol>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 22 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/cross-pair/">Cross-pair chaining, control parallel trends and within-unit weighting&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Treatment adjustment</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/treatment/</guid><description>&lt;p>When baseline covariates shift both which units enter treatment and how untreated outcomes evolve over time, &lt;code>cdid&lt;/code> adjusts each two-date comparison for covariates through the &lt;code>method()&lt;/code> option (and &lt;code>outcomepooling()&lt;/code> when an outcome regression is fitted):&lt;/p>
&lt;ul>
&lt;li>&lt;code>method(dr)&lt;/code> (default): doubly robust adjustment combining treatment propensity weighting and control outcome-change regression,&lt;/li>
&lt;li>&lt;code>method(reg)&lt;/code>: outcome regression (OR) adjustment using control outcome-change regression,&lt;/li>
&lt;li>&lt;code>method(ipw)&lt;/code>: inverse probability weighting (IPW) using risk-set treatment propensity logits.&lt;/li>
&lt;/ul>
&lt;p>This page defines the treatment adjustment models in &lt;code>mode(chained)&lt;/code>, explains how &lt;code>cdid&lt;/code> parameterizes covariates, comparison-block outcome pooling (&lt;code>outcomepooling(separate|pooled)&lt;/code>), and calendar duration steps $L(e)$, and shows how to specify and compare the methods in Stata.&lt;/p>
&lt;h2 id="1-specifying-treatment-covariates-in-stata">1. Specifying treatment covariates in Stata&lt;/h2>
&lt;p>The Stata snippets on this page use the simulated panel and the global &lt;code>CDID_DEMO_BITERS&lt;/code> created by Sections 0 and 1 of the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/hands-on/">hands-on do-file&lt;/a>; run those sections first.&lt;/p>
&lt;p>Supply baseline covariates either as &lt;code>indepvars&lt;/code> immediately after &lt;code>depvar&lt;/code> or inside &lt;code>covars(varlist)&lt;/code> (do not pass non-empty lists to both simultaneously), and pass &lt;code>framecovars(varlist)&lt;/code> when using a population frame &lt;code>frame(name)&lt;/code>:&lt;/p>
&lt;pre>&lt;code class="language-stata">* Equivalent ways to specify covariates x_bin and x_cont:
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) method(dr) controlgroup(nevertreated) baseperiod(varying) biters($CDID_DEMO_BITERS)
cdid y, ivar(id) time(period) gvar(first_treat) covars(x_bin x_cont) method(dr) bstrap(0) cband(0)
&lt;/code>&lt;/pre>
&lt;ul>
&lt;li>&lt;strong>Intercept handling:&lt;/strong> By default, both the treatment propensity logits and the control outcome-change regression include local intercepts. Specify &lt;code>noconstant&lt;/code> to omit the intercepts; the support and rank checks still apply.&lt;/li>
&lt;li>&lt;strong>Factor variables:&lt;/strong> Standard Stata factor-variable notation (&lt;code>i.group&lt;/code>, &lt;code>c.x_bin#c.x_cont&lt;/code>) is supported.&lt;/li>
&lt;li>&lt;strong>Separate observation-model covariates:&lt;/strong> &lt;code>indepvars&lt;/code> / &lt;code>covars()&lt;/code> define the design $z(X)$ used by the treatment propensity model $p$, the counterfactual control outcome regression $m$, and, when it is used, the actual-change imputer $j$. Observation-probability logits $q$ under &lt;code>selection(conditional_mtar)&lt;/code> inherit &lt;code>covars()&lt;/code> by default or use a separate list via &lt;code>selcovars(varlist)&lt;/code> (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/#separate-covariate-lists-covars-vs-selcovars">Handling missing outcomes&lt;/a>).&lt;/li>
&lt;/ul>
&lt;h2 id="2-the-three-treatment-adjustment-methods">2. The three treatment adjustment methods&lt;/h2>
&lt;p>For each comparison $l$ pairing a target cohort $g$, an ordered calendar pair $e = (s, t)$ with $s &amp;lt; t$, and a control cohort set $K$, let $\tilde{\Delta}&lt;em>{i,e}$ and $\tilde{w}&lt;/em>{i,e}$ denote the outcome change and unit weight produced by the correction for missing outcomes (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/">Handling missing outcomes&lt;/a>). Treatment adjustment forms the comparison estimate $\hat{\mu}&lt;em>l$ from $(\tilde{\Delta}&lt;/em>{i,e}, \tilde{w}_{i,e})$ as follows:&lt;/p>
&lt;h3 id="inverse-probability-weighting-methodipw">Inverse probability weighting (&lt;code>method(ipw)&lt;/code>)&lt;/h3>
&lt;p>For each distinct risk set $(g, K, e)$, &lt;code>cdid&lt;/code> fits a weighted binary logit $p_{g,K,e}(X)$ for membership in target cohort $g$ versus control pool $K$, and reweights control changes by the estimated odds $\frac{\hat{p}&lt;em>{g,K,e}(X_i)}{1 - \hat{p}&lt;/em>{g,K,e}(X_i)}$ using Hajek (self-normalized) weights.&lt;/p>
&lt;h3 id="control-outcome-change-regression-methodreg-and-outcomepooling">Control outcome-change regression (&lt;code>method(reg)&lt;/code>) and &lt;code>outcomepooling()&lt;/code>&lt;/h3>
&lt;p>Rather than refitting the same outcome regression for every comparison that shares a control risk set, &lt;code>mode(chained)&lt;/code> groups the comparisons into blocks $b = (e, K)$: the distinct pairs of a date pair $e = (s, t)$ and a control group $K$. How &lt;code>cdid&lt;/code> parameterizes the covariate slopes across those blocks is controlled by &lt;code>outcomepooling(separate|pooled)&lt;/code> (stored in &lt;code>e(outcome_pooling)&lt;/code>):&lt;/p>
&lt;ul>
&lt;li>&lt;strong>&lt;code>outcomepooling(separate)&lt;/code> (default):&lt;/strong> Fits a separate weighted least squares regression on each comparison block $b = (e, K)$:&lt;/li>
&lt;/ul>
&lt;p>$$m_b(X_i) = \alpha_b + L(e), z(X_i)'\beta_b$$&lt;/p>
&lt;ul>
&lt;li>&lt;strong>&lt;code>outcomepooling(pooled)&lt;/code>:&lt;/strong> Fits one joint weighted least squares regression across all comparison blocks $b = (e, K)$ simultaneously with a shared per-step slope vector $\beta$:&lt;/li>
&lt;/ul>
&lt;p>$$m_b(X_i) = \alpha_b + L(e), z(X_i)'\beta$$&lt;/p>
&lt;p>where:&lt;/p>
&lt;ul>
&lt;li>$\alpha_b$ is a local intercept specific to block $b = (e, K)$ (present unless &lt;code>noconstant&lt;/code> is specified), allowing arbitrary baseline untreated time trends across every pair $(s, t)$ and control set $K$,&lt;/li>
&lt;li>$z(X_i)$ is the non-constant covariate vector from &lt;code>covars()&lt;/code> / &lt;code>indepvars&lt;/code>,&lt;/li>
&lt;li>$\beta_b$ (&lt;code>separate&lt;/code>) is a block-specific slope vector for $(e, K)$, whereas $\beta$ (&lt;code>pooled&lt;/code>) is a single slope vector shared across all blocks $b$,&lt;/li>
&lt;li>$L(e) = i_t - i_s \ge 1$ is the &lt;strong>number of calendar steps&lt;/strong> between the index $i_s$ of date $s$ and the index $i_t$ of date $t$ in the sorted stored calendar.&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>[!IMPORTANT]
&lt;strong>Calendar step count $L(e)$ vs raw date subtraction $t - s$:&lt;/strong> &lt;code>cdid&lt;/code> always defines $L(e) = i_t - i_s$ as the number of transitions in the stored calendar, never the arithmetic difference $t - s$ of the numeric labels. For example, if your panel is biennial with stored dates 2014, 2016, 2018 and 2020, the pair $(2014, 2016)$ has $L(e) = 2 - 1 = 1$ step and $(2014, 2018)$ has $L(e) = 3 - 1 = 2$ steps.&lt;/p>
&lt;/blockquote>
&lt;p>After fitting the block regression(s), &lt;code>method(reg)&lt;/code> subtracts the predicted counterfactual change $\hat{m}_b(X_i)$ from the treated cohort&amp;rsquo;s change on block $b$. Under &lt;code>method(ipw)&lt;/code> or &lt;code>method(custom)&lt;/code>, &lt;code>outcomepooling()&lt;/code> does not apply (&lt;code>e(outcome_pooling)&lt;/code> is empty and &lt;code>outcomepooling()&lt;/code> is listed first in &lt;code>e(inactive_options)&lt;/code>).&lt;/p>
&lt;h3 id="doubly-robust-adjustment-methoddr-default">Doubly robust adjustment (&lt;code>method(dr)&lt;/code>, default)&lt;/h3>
&lt;p>&lt;code>method(dr)&lt;/code> combines both models: it subtracts the control outcome-change regression prediction $\hat{m}&lt;em>b(X_i)$ (fitted under &lt;code>outcomepooling(separate)&lt;/code> by default, or &lt;code>outcomepooling(pooled)&lt;/code>) from both treated and control changes and applies inverse propensity odds weights from $\hat{p}&lt;/em>{g,K,e}(X_i)$ to the control residuals. Under &lt;code>selection(none)&lt;/code> (or when combined with a valid missing-outcome adjustment), &lt;code>method(dr)&lt;/code> is consistent for each comparison link if &lt;strong>either&lt;/strong> the treatment propensity logit $p$ &lt;strong>or&lt;/strong> the control outcome-change regression $m$ is correctly specified (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/robustness/">Compare model robustness&lt;/a>).&lt;/p>
&lt;h2 id="3-change-imputation-uses-a-different-regression">3. Change imputation uses a different regression&lt;/h2>
&lt;p>Do not confuse the counterfactual control regression $m_b(X)$ of &lt;code>method(reg|dr)&lt;/code> with the actual-change imputation model $j_c(X)$ of &lt;code>selmethod(imputation|dr)&lt;/code> (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/methods/missing-outcomes/#2-change-imputation-selmethodimputation">Handling missing outcomes&lt;/a>):&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Feature&lt;/th>
&lt;th>Counterfactual control regression $m_b(X)$&lt;/th>
&lt;th>Actual-change imputer $j_c(X)$&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Used with&lt;/td>
&lt;td>&lt;code>method(reg)&lt;/code> or &lt;code>method(dr)&lt;/code>&lt;/td>
&lt;td>&lt;code>selection(conditional_mtar)&lt;/code> with &lt;code>selmethod(imputation)&lt;/code> or &lt;code>selmethod(dr)&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Fitted on&lt;/td>
&lt;td>Control cohorts $G_i \in K$ on comparison blocks $b = (e, K)$&lt;/td>
&lt;td>Observed pairs ($S_e = 1$) within each individual cohort $k$ (both treated and control)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Predicts&lt;/td>
&lt;td>Counterfactual &lt;strong>untreated&lt;/strong> change $\Delta_e Y(0)$&lt;/td>
&lt;td>&lt;strong>Actual&lt;/strong> cohort change $\Delta_e Y$ (including treatment effects for treated cohorts)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Slope sharing&lt;/td>
&lt;td>Controlled by &lt;code>outcomepooling(separate|pooled)&lt;/code> (default &lt;code>separate&lt;/code> per block $b$; &lt;code>pooled&lt;/code> shares $\beta$ across blocks)&lt;/td>
&lt;td>Controlled by &lt;code>imppooling(separate|within_cohort|across_cohorts)&lt;/code> (default &lt;code>separate&lt;/code>)&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="4-propensity-safeguard-and-collinearity-handling">4. Propensity safeguard and collinearity handling&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Propensity score bound (&lt;code>1 - 1e-6&lt;/code>):&lt;/strong> As in R &lt;code>cdid&lt;/code>, fitted treatment propensities $\hat{p}_{g,K,e}(X_i)$ are capped above at $1 - 10^{-6} = 0.999999$ so that inverse odds $\hat{p}/(1 - \hat{p})$ remain finite without dropping observations. The number of bounded propensities is shown when it was stored with the results; otherwise &lt;code>cdid_diagnostics&lt;/code> reports it as not retained.&lt;/li>
&lt;li>&lt;strong>Collinearity and rank checks:&lt;/strong> In the control outcome-change regression $m$ (whether fitted per block under &lt;code>outcomepooling(separate)&lt;/code> or jointly under &lt;code>outcomepooling(pooled)&lt;/code>), exactly collinear covariates are dropped only when the counterfactual predictions do not depend on them, on the support of the block&amp;rsquo;s control and target units; if a required prediction is not identified or a treatment logit has no interior estimate, estimation stops with a support, rank or convergence error (separation: error 459; a boundary estimate or nonconvergence: error 430); &lt;code>cdid&lt;/code> does not change the estimator (&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/troubleshooting/">Diagnose errors and unavailable results&lt;/a>).&lt;/li>
&lt;/ul>
&lt;h2 id="5-comparing-the-built-in-methods-in-stata">5. Comparing the built-in methods in Stata&lt;/h2>
&lt;p>Sections 3a and 3d of the hands-on do-file estimate the same specification with DR (with the default &lt;code>outcomepooling(separate)&lt;/code> and with &lt;code>outcomepooling(pooled)&lt;/code>), IPW and OR. The do-file uses few bootstrap draws; the results neither rank the methods by precision nor show that any model is correct:&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) biters($CDID_DEMO_BITERS)
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(dr) outcomepooling(pooled) biters($CDID_DEMO_BITERS)
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(ipw) biters($CDID_DEMO_BITERS)
cdid y x_bin x_cont, ivar(id) time(period) gvar(first_treat) ///
method(reg) biters($CDID_DEMO_BITERS)
&lt;/code>&lt;/pre>
&lt;p>See &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/treatment-choice/">Treatment choice&lt;/a> for the algebra of the risk-set logits and the qualifications on shared slopes.&lt;/p>
&lt;hr>
&lt;p>&lt;strong>Reading path, step 7 of 22&lt;/strong> · Previous: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/help/prepare-data/">Prepare your panel and unit table&lt;/a> · Next: &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/examples/treatment-choice/">Choose IPW, OR or DR in an incomplete panel&lt;/a>&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>When treatment can stop and restart</title><link>https://www.davidbenatia.com/tools/cdid/stata/methods/switching/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/methods/switching/</guid><description>&lt;p>With &lt;code>dvar(varname)&lt;/code> in place of &lt;code>gvar()&lt;/code>, &lt;code>cdid&lt;/code> estimates the effects of a binary treatment that units may enter, leave, and enter again. &lt;code>varname&lt;/code> records the treatment status $D_{it} \in {0, 1}$ of unit $i$ at date $t$. This page defines the estimated cells and their average, the adjustment methods, the handling of missing outcomes and the inference. The syntax is in &lt;code>help cdid_dvar&lt;/code>; the design corresponds to &lt;code>att_gt(dname = ...)&lt;/code> of the R package &lt;code>cdid&lt;/code> 1.3.0.0.&lt;/p>
&lt;h2 id="first-treatment-date-or-current-treatment-status">First treatment date or current treatment status?&lt;/h2>
&lt;p>Use &lt;code>gvar()&lt;/code> when treatment is absorbing and you want effects that may evolve with time since adoption, aggregated by &lt;code>estat&lt;/code>. Use &lt;code>dvar()&lt;/code> when units can leave and re-enter treatment and the effect of interest is the immediate effect of current status, under the assumption that past treatment has no lingering effect. Supplying both is an error, and absorbing data supplied through &lt;code>dvar()&lt;/code> still request the static model and its targets.&lt;/p>
&lt;h2 id="what-your-input-needs">What your input needs&lt;/h2>
&lt;p>&lt;code>dvar()&lt;/code> requires one row for every unit at every date, a treatment status, 0 or 1, in every row, including rows whose outcome is missing, and nonmissing covariates at $t-1$ for the units at risk of switching at $t$. Outcomes may be missing. Covariates may vary over time. Weights, &lt;code>saving()&lt;/code> and the options for comparison groups, anticipation, base periods, parallel-trends restrictions and cross-pair chaining do not apply; &lt;code>missingreference(exclude)&lt;/code> is refused.&lt;/p>
&lt;h2 id="assumptions-and-cells">Assumptions and cells&lt;/h2>
&lt;p>The design assumes that outcomes depend on the current treatment status only, $Y_{it} = Y_{it}(D_{it})$ (no carryover), and that, conditional on the covariates at the earlier date, units that change status and units that keep it would have followed the same untreated or treated outcome path.&lt;/p>
&lt;p>For a date $t$ after the first and a prior status $d \in {0, 1}$, cell $c = (t, d)$ is defined on the risk set $R_c = 1{D_{i,t-1} = d}$:&lt;/p>
&lt;ul>
&lt;li>switchers $G_c = R_c, 1{D_{it} = 1 - d}$ (entries for $d = 0$, exits for $d = 1$);&lt;/li>
&lt;li>stayers $C_c = R_c, 1{D_{it} = d}$.&lt;/li>
&lt;/ul>
&lt;p>With $\Delta Y_{ic} = Y_{it} - Y_{i,t-1}$ and covariates $X_{ic} = X_{i,t-1}$, the cell contrast is&lt;/p>
&lt;p>$$
\theta_c = E[\Delta Y_{c} \mid G_c = 1] - E\big[, E[\Delta Y_{c} \mid C_c = 1, X_c] \mid G_c = 1 \big] = E[Y_t(1-d) - Y_t(d) \mid G_c = 1],
$$&lt;/p>
&lt;p>and the reported effect is $\tau_c = \sigma_c \theta_c$ with $\sigma_c = 1 - 2d$. Every reported effect is therefore the effect on the switchers of being treated rather than untreated at date $t$: for entries, $E[Y_t(1) - Y_t(0) \mid G_c = 1]$; for exits, the same contrast for the units that leave treatment. &lt;code>e(cells)&lt;/code> reports both $\theta_c$ (&lt;code>theta&lt;/code>) and $\tau_c$ (&lt;code>att&lt;/code>).&lt;/p>
&lt;h2 id="adjustment-methods">Adjustment methods&lt;/h2>
&lt;p>Let $\pi_c(x)$ be the probability of switching given $R_c = 1$ and $X_c = x$, fitted by a logit on the switchers and stayers of the cell, and $r_c(x) = \pi_c(x) / (1 - \pi_c(x))$ its odds. Let $m_c(x) = \alpha_c + x'\beta$ be a least-squares regression of the stayers' outcome changes on the covariates.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Method&lt;/th>
&lt;th>Estimator of $\theta_c$&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>method(ipw)&lt;/code>&lt;/td>
&lt;td>$\bar{\Delta}&lt;em>{G_c} - \sum&lt;/em>{C_c} r_c(X_i), \Delta Y_{ic} \big/ \sum_{C_c} r_c(X_i)$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>method(reg)&lt;/code>&lt;/td>
&lt;td>mean over the switchers of $\Delta Y_{ic} - m_c(X_{ic})$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>method(dr)&lt;/code> (default)&lt;/td>
&lt;td>mean over the switchers of $\Delta Y_{ic} - m_c(X_{ic})$, minus the odds-weighted mean over the stayers of the same residual&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>With &lt;code>outcomepooling(separate)&lt;/code> (default), each cell has its own regression. With &lt;code>outcomepooling(pooled)&lt;/code>, the regression has an intercept $\alpha_c$ for each requested cell and slopes $\beta$ common to all requested cells, fitted on their stayers. A partition such as &lt;code>outcomepooling(entry:2003 entry:2004 | exit:2003 exit:2004)&lt;/code> fits common slopes $\beta_b$ within each block $b$ of cells, again with an intercept for each cell; every requested cell must belong to one block. A block may include cells that are not requested (for example the exit cells with &lt;code>switchers(entry)&lt;/code>), whose stayers then contribute only to the fit of $\beta_b$; this is available in complete panels only. Covariates may vary over time; each cell uses their values at $t - 1$.&lt;/p>
&lt;h2 id="missing-outcomes">Missing outcomes&lt;/h2>
&lt;p>When outcomes are missing, the change of each role from $t-1$ to $t$ is chained through the dates at which its units are observed. For cell $c$ and role $a \in {G, C}$, every pair of dates $s &amp;lt; u$ at which at least one unit of the role has observed outcomes is an edge of the role graph, with moment&lt;/p>
&lt;p>$$
\hat\psi^a_{c,(s,u)} = \frac{\sum_i A_{ic} O_{is} O_{iu} h_{ic} (Y_{iu} - Y_{is})}{\sum_i A_{ic} O_{is} O_{iu} h_{ic}},
$$&lt;/p>
&lt;p>where $A_{ic}$ is the role indicator, $O_{is}$ indicates an observed outcome, and $h_{ic} = r_c(X_{ic})$ for the stayers under &lt;code>method(ipw)&lt;/code> and &lt;code>method(dr)&lt;/code> ($h_{ic} = 1$ otherwise). The levels of every role at its observed dates, relative to $t-1$, are estimated jointly for all requested cells by GMM, with &lt;code>gmmweighting(optimal)&lt;/code> (default; Tikhonov regularization controlled by &lt;code>condition()&lt;/code> and &lt;code>ridge()&lt;/code>) or &lt;code>gmmweighting(identity)&lt;/code>; each cell contrast is the switchers' level at $t$ minus the stayers' level at $t$.&lt;/p>
&lt;p>With &lt;code>method(reg)&lt;/code> or &lt;code>method(dr)&lt;/code>, the stayer regression is reconstructed from the graph: the stayers' mean change $m_c$ and its covariance with the covariates combine the observed edges along the least-squares path from $t-1$ to $t$, the slopes solve the pooled normal equations with the covariate moments of all stayers, and $\alpha_c = m_c - \bar z_c'\beta$. Every edge that spans the switch ($s &amp;lt; t \le u$) is then centered by the predicted change $\alpha_c + \bar z'\beta$, evaluated at the switchers' covariate mean for the switchers and at the odds-weighted stayers' covariate mean for the stayers; under &lt;code>method(reg)&lt;/code> only the switchers' links enter the GMM.&lt;/p>
&lt;p>The design assumes that the units of a role observed at a pair of dates have the same expected outcome change as the whole role. A cell is unavailable (&lt;code>status&lt;/code> 3 or 4 in &lt;code>e(cells)&lt;/code>) when the observed dates of its switchers or of its stayers do not connect $t-1$ and $t$.&lt;/p>
&lt;h3 id="observation-models">Observation models&lt;/h3>
&lt;p>With &lt;code>selection(conditional_mtar)&lt;/code>, the probability that outcomes are observed may depend on the covariates at $t-1$ within each role. Let $S_{i,(s,u)} = O_{is} O_{iu}$, $q_{ic,(s,u)}$ its fitted probability, and $j_{ic,(s,u)}$ the predicted change from a regression of the observed changes on the covariates. The edge moments become&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>&lt;code>selmethod()&lt;/code>&lt;/th>
&lt;th>Weight on unit $i$&lt;/th>
&lt;th>Change&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>ipw&lt;/code> (default)&lt;/td>
&lt;td>$A_{ic} h_{ic} S_{i,(s,u)} / \max(q_{ic,(s,u)}, 10^{-6})$&lt;/td>
&lt;td>$Y_{iu} - Y_{is}$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>imputation&lt;/code>&lt;/td>
&lt;td>$A_{ic} h_{ic}$&lt;/td>
&lt;td>$j_{ic,(s,u)}$&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>dr&lt;/code>&lt;/td>
&lt;td>$A_{ic} h_{ic}$&lt;/td>
&lt;td>$j_{ic,(s,u)} + S_{i,(s,u)} (Y_{iu} - Y_{is} - j_{ic,(s,u)}) / \max(q_{ic,(s,u)}, 10^{-6})$&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;code>selmodel(pair_logit)&lt;/code> (default) fits $q$ by a logit for each pair; &lt;code>selmodel(independent_period_logit)&lt;/code> fits a logit for each date and multiplies the two probabilities; it assumes that, given the covariates, observation at the two dates is independent. Every logit and imputation regression has an intercept for each role and pair (or date) and slopes shared within a block: &lt;code>separate&lt;/code> (each role and pair), &lt;code>within_group&lt;/code> (each role of a transition), or &lt;code>pooled&lt;/code> (all), set by &lt;code>selpooling()&lt;/code> and &lt;code>imppooling()&lt;/code>. With &lt;code>impscale(per_period)&lt;/code> (default), the covariates of a pair are multiplied by its number of periods. The observation logits use &lt;code>selcovars()&lt;/code> (default: the outcome covariates) or an intercept only with &lt;code>selconstant&lt;/code>. &lt;code>seluniverse(B)&lt;/code> or &lt;code>seluniverse(A)&lt;/code> fits the pair logits on the units with at least one or at least two observed outcomes, with an optional known ratio &lt;code>selrho()&lt;/code> constant within units; it requires &lt;code>selmethod(ipw)&lt;/code>, &lt;code>selmodel(pair_logit)&lt;/code> and &lt;code>seljustification()&lt;/code>. The influence functions of all edge moments include the estimation of these models.&lt;/p>
&lt;h3 id="fitted-models">Fitted models&lt;/h3>
&lt;p>With &lt;code>keepnuisance&lt;/code>, &lt;code>cdid_nuisance&lt;/code> reports the switcher logits of the transitions (&lt;code>treatment&lt;/code>), the stayer outcome-change regressions (&lt;code>outcome&lt;/code>), the observation logits (&lt;code>selection&lt;/code>) and the imputation regressions (&lt;code>imputation&lt;/code>), with standard errors from the same original-unit influence functions as the effects.&lt;/p>
&lt;h2 id="requested-cells-and-the-average">Requested cells and the average&lt;/h2>
&lt;p>&lt;code>switchers(both|entry|exit)&lt;/code> selects the directions. By default, the requested cells are those with at least one switcher in the requested directions. &lt;code>switchtimes(numlist)&lt;/code> requests the cells at the listed dates; a listed cell without switchers or stayers is reported as unavailable.&lt;/p>
&lt;p>The average weights the effects of the requested cells by their numbers of switchers $N_c$:&lt;/p>
&lt;p>$$
\delta = \sum_{c} \omega_c \tau_c, \qquad \omega_c = \frac{N_c}{\sum_{c'} N_{c'}}.
$$&lt;/p>
&lt;p>It is reported in &lt;code>e(att)&lt;/code> only when every requested cell is estimable; it is never renormalized over a subset of cells.&lt;/p>
&lt;h2 id="inference">Inference&lt;/h2>
&lt;p>The influence function of each $\hat\tau_c$ accounts for the estimated logit and regression; that of $\hat\delta$ also accounts for the estimated switcher shares. Analytical standard errors sum the influence functions within clusters (&lt;code>cluster()&lt;/code>; units otherwise), center the cluster sums, and divide by the number of units. With &lt;code>bstrap(1)&lt;/code> (default), the multiplier bootstrap draws one Rademacher sign per cluster and reports the interquartile-range standard error; with &lt;code>cband(1)&lt;/code> (default), the bounds of the cells are simultaneous, from the bootstrap distribution of the maximum $t$-statistic over the estimable cells. The average uses the same draws, has a pointwise interval, and does not enter the band. &lt;code>e(V)&lt;/code> holds the analytical covariance of the cells in &lt;code>e(b)&lt;/code>.&lt;/p>
&lt;h2 id="example">Example&lt;/h2>
&lt;pre>&lt;code class="language-stata">clear
set seed 2027
set obs 300
generate long id = _n
generate double x = rnormal()
expand 6
bysort id: generate year = 2000 + _n
generate byte treated = runiform() &amp;lt; invlogit(-1 + .5*x)
generate double y = 0.3*(year - 2000) + 0.5*x + treated + rnormal()
* entries and exits at every date, doubly robust
cdid y x, ivar(id) time(year) dvar(treated)
* entries only, outcome regression with common slopes, analytical inference
cdid y x, ivar(id) time(year) dvar(treated) switchers(entry) method(reg) outcomepooling(pooled) bstrap(0) cband(0)
* cells at two dates and a comparison of entry and exit effects
cdid y x, ivar(id) time(year) dvar(treated) switchtimes(2003 2004) bstrap(0) cband(0)
lincom _b[entry:t2003] - _b[exit:t2003]
cdid_export using cells.dta, type(cells) replace
* outcomes missing at some dates: the changes are chained through the observed dates
replace y = . if runiform() &amp;lt; .15
cdid y x, ivar(id) time(year) dvar(treated) bstrap(0) cband(0)
* augmented correction using x, and the fitted models
cdid y x, ivar(id) time(year) dvar(treated) selection(conditional_mtar) selmethod(dr) selpooling(pooled) imppooling(pooled) keepnuisance bstrap(0) cband(0)
cdid_nuisance
cdid_nuisance selection
&lt;/code>&lt;/pre>
&lt;h2 id="after-estimation">After estimation&lt;/h2>
&lt;p>&lt;code>cdid_export&lt;/code> saves &lt;code>type(cells)&lt;/code> and &lt;code>type(aggregate)&lt;/code>, and &lt;code>cdid_nuisance&lt;/code> reports the fitted models when &lt;code>keepnuisance&lt;/code> is specified. &lt;code>estat&lt;/code>, &lt;code>cdid_plot&lt;/code>, &lt;code>cdid_chain&lt;/code> and &lt;code>cdid_diagnostics&lt;/code> are not available. The stored results are listed in the &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/#results-of-cdid-with-dvar">results reference&lt;/a>.&lt;/p>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>de Chaisemartin, C., D&amp;rsquo;Haultfoeuille, X., Pasquier, F., Sow, D. and Vazquez-Bare, G. (2026). Difference-in-Differences Estimators for Treatments Continuously Distributed at Every Period. Working paper, arXiv:2201.06898v7. &lt;a href="https://arxiv.org/abs/2201.06898v7" target="_blank" rel="noopener">https://arxiv.org/abs/2201.06898v7&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>The &lt;code>dvar()&lt;/code> model adapts their static binary specialization to complete and incomplete panels.&lt;/p>
&lt;hr>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a> · &lt;a href="https://github.com/dvbn/cdid-stata/blob/6089bac8b83e8826c05467f47d308782cc3992db/README.md" target="_blank" rel="noopener">Package overview&lt;/a>&lt;/p></description></item><item><title>Working with cdid results</title><link>https://www.davidbenatia.com/tools/cdid/stata/user-results/</link><pubDate>Mon, 16 Nov 2026 00:00:00 +0000</pubDate><guid>https://www.davidbenatia.com/tools/cdid/stata/user-results/</guid><description>&lt;p>This page explains how results move between &lt;code>cdid&lt;/code>, &lt;code>estat&lt;/code> and the commands that use them. &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/reference/results/">Results&lt;/a> lists every stored result.&lt;/p>
&lt;h2 id="replay-store-and-restore">Replay, store and restore&lt;/h2>
&lt;p>&lt;code>cdid&lt;/code> posts its results in &lt;code>e()&lt;/code>; typing &lt;code>cdid&lt;/code> alone replays them. &lt;code>estat&lt;/code> replaces them with the aggregation, while the group-time results remain available to later &lt;code>estat&lt;/code> commands. After &lt;code>estat&lt;/code>, &lt;code>cdid_chain&lt;/code> still reports the comparisons of the fit in the same session; &lt;code>cdid_nuisance&lt;/code> needs the fit to be the current result, so store the fit before aggregating and restore it afterwards:&lt;/p>
&lt;pre>&lt;code class="language-stata">clear
set seed 20261116
set obs 600
generate id = _n
generate G = cond(runiform() &amp;lt; .4, 0, cond(runiform() &amp;lt; .5, 2004, 2006))
generate x = rnormal()
expand 8
bysort id: generate year = 2000 + _n
generate y = x + .2*(year - 2000) + (G &amp;gt; 0 &amp;amp; year &amp;gt;= G)*(1 + .25*(year - G)) + rnormal()
replace y = . if runiform() &amp;lt; .2
cdid y x, ivar(id) time(year) gvar(G) bstrap(0) cband(0)
estimates store fit
estat dynamic
cdid_chain, cohort(2004)
estimates restore fit
cdid
&lt;/code>&lt;/pre>
&lt;h2 id="commands-that-use-the-stored-results">Commands that use the stored results&lt;/h2>
&lt;p>None of the following commands uses the data in memory, refits a model or draws random numbers, and each leaves the data, &lt;code>e()&lt;/code> and the random-number state as they were.&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Command&lt;/th>
&lt;th>Purpose&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>cdid_export using file, type(...)&lt;/code>&lt;/td>
&lt;td>Save the results as a Stata dataset.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_diagnostics [, detail]&lt;/code>&lt;/td>
&lt;td>Display the population, the cells, the settings, the inference and the tests; return them in &lt;code>r()&lt;/code>.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_plot [, ...]&lt;/code>&lt;/td>
&lt;td>Graph the estimates and their intervals.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_chain [, ...]&lt;/code>&lt;/td>
&lt;td>Show the comparisons and GMM weights behind each effect.&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>cdid_nuisance [component]&lt;/code>&lt;/td>
&lt;td>Report the fitted models kept with &lt;code>keepnuisance&lt;/code> in chained mode. After ordinary results, returns &lt;code>r(status) = &amp;quot;unavailable&amp;quot;&lt;/code> and &lt;code>r(reason)&lt;/code>.&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="datasets-written-by-cdid_export">Datasets written by cdid_export&lt;/h2>
&lt;ul>
&lt;li>&lt;code>type(cells)&lt;/code>, the default: every requested cell, including pretreatment, reference and unavailable cells, with the reason a cell is unavailable.&lt;/li>
&lt;li>&lt;code>type(aggregate)&lt;/code>: the current aggregation of &lt;code>estat&lt;/code> (bins, overall estimate, and the cells of each bin with their weights).&lt;/li>
&lt;li>&lt;code>type(units)&lt;/code>: every unit of the study population, including units supplied only through &lt;code>frame()&lt;/code>, with its identifier, cohort, weight and cluster.&lt;/li>
&lt;li>&lt;code>type(influence)&lt;/code>: the influence functions in long form, one row per unit and estimate.&lt;/li>
&lt;li>&lt;code>type(summary)&lt;/code>: every setting and result as key-value rows.&lt;/li>
&lt;/ul>
&lt;p>The variable &lt;code>se&lt;/code> holds the reported standard error, from the multiplier bootstrap when it was used, and &lt;code>analytic_se&lt;/code> the analytical one. &lt;code>lower&lt;/code> and &lt;code>upper&lt;/code> hold the reported pointwise interval or simultaneous band, and &lt;code>interval_kind&lt;/code> says which. After an aggregation, &lt;code>type(cells)&lt;/code> still describes the group-time cells. With &lt;code>noinffunc&lt;/code>, standard errors and intervals are missing. After &lt;code>dvar()&lt;/code> estimation, only &lt;code>type(cells)&lt;/code> and &lt;code>type(aggregate)&lt;/code> are available. The file name must have the extension &lt;code>.dta&lt;/code> or none, and an existing file is overwritten only with &lt;code>replace&lt;/code>.&lt;/p>
&lt;pre>&lt;code class="language-stata">cdid_export using cdid_cells, type(cells) replace
estat dynamic
cdid_export using cdid_dynamic, type(aggregate) replace
cdid_plot, export(cdid_dynamic.png, replace)
&lt;/code>&lt;/pre>
&lt;h2 id="saved-results">Saved results&lt;/h2>
&lt;p>&lt;code>saving(filename)&lt;/code> with &lt;code>cdid&lt;/code>, &lt;code>estat&lt;/code> or &lt;code>cdid_pretest&lt;/code> writes the complete results, including the influence functions, the reports kept with &lt;code>keepnuisance&lt;/code>, the record of units excluded under &lt;code>missingreference(exclude)&lt;/code> and, for files saved by &lt;code>cdid&lt;/code>, the information used by &lt;code>cdid_chain&lt;/code>. File names created by &lt;code>tempfile&lt;/code> are accepted. &lt;code>cdid_load&lt;/code> restores the results of &lt;code>cdid&lt;/code> and &lt;code>estat&lt;/code> into &lt;code>e()&lt;/code> without the data, and &lt;code>cdid_pretest_load&lt;/code> restores the results of &lt;code>cdid_pretest&lt;/code> into &lt;code>r()&lt;/code>. These files differ from the datasets written by &lt;code>cdid_export&lt;/code>, and &lt;code>saving()&lt;/code> never overwrites an existing file. Results of &lt;code>dvar()&lt;/code> estimation cannot be saved.&lt;/p>
&lt;pre>&lt;code class="language-stata">tempfile fit
cdid y x, ivar(id) time(year) gvar(G) bstrap(0) cband(0) saving(`fit')
clear
cdid_load using `fit'
estat group
&lt;/code>&lt;/pre>
&lt;p>After &lt;code>cdid_load&lt;/code>, &lt;code>e(cmdline)&lt;/code> holds the original &lt;code>cdid&lt;/code> command, including when the file contains an aggregation. For older files without the original command line, it holds the &lt;code>cdid_load&lt;/code> command. &lt;code>e(state_file)&lt;/code> names the file. &lt;code>e(sample)&lt;/code> is unset because the results no longer refer to data in memory.&lt;/p>
&lt;h2 id="large-problems">Large problems&lt;/h2>
&lt;p>&lt;code>posting(matrix)&lt;/code>, the default, posts &lt;code>e(b)&lt;/code> and &lt;code>e(V)&lt;/code>. When the number of estimates exceeds Stata&amp;rsquo;s matrix size, &lt;code>posting(state)&lt;/code> keeps the complete results without posting them; &lt;code>estat&lt;/code>, &lt;code>cdid_export&lt;/code> and &lt;code>cdid_plot&lt;/code> still work. &lt;code>workspace()&lt;/code>, &lt;code>chunk()&lt;/code> and &lt;code>workcap()&lt;/code> limit memory and computation; see &lt;a href="https://www.davidbenatia.com/tools/cdid/stata/performance/">Performance&lt;/a>.&lt;/p>
&lt;p>&lt;a href="https://www.davidbenatia.com/tools/cdid/stata/">Guide home&lt;/a>&lt;/p></description></item></channel></rss>