Tuesday, January 20, 2026

A number of-equation fashions: Estimation and marginal results utilizing gmm


We estimate the common therapy impact (ATE) for an exponential imply mannequin with an endogenous therapy. Now we have a two-step estimation downside the place step one corresponds to the therapy mannequin and the second to the result mannequin. As proven in Utilizing gmm to resolve two-step estimation issues, this may be solved with the generalized technique of moments utilizing gmm.

This continues the collection of posts the place we illustrate methods to acquire appropriate customary errors and marginal results for fashions with a number of steps. Within the earlier posts, we used gsem and mlexp to estimate the parameters of fashions with separable likelihoods. Within the present mannequin, as a result of the therapy is endogenous, the chance for the mannequin is not separable. We display how we are able to use gmm to estimate the parameters in these conditions.

Mannequin

We start by describing the potential-outcome framework used to outline a median therapy impact. For every therapy stage, there may be an end result that we’d observe if an individual had been to obtain that therapy stage. When we have now an end result with an exponential imply and there are two therapy ranges, we are able to specify how the technique of the potential outcomes (y_{0i}) and (y_{1i}) are generated from the regressors ({bf x}_i) and error phrases (epsilon_{0i}) and (epsilon_{1i}),

start{eqnarray*}
E(y_{0i}vert{bf x}_i,epsilon_{0i}) &=& exp({bf x}_i{boldsymbol beta}_0 + beta_{00}+epsilon_{0i}) cr
E(y_{1i}vert{bf x}_i,epsilon_{1i}) &=& exp({bf x}_i{boldsymbol beta}_1 + beta_{10}+epsilon_{1i})
finish{eqnarray*}

the place the parameters (beta_{00}) and (beta_{10}) are fixed intercepts and ({boldsymbol beta}_0) and ({boldsymbol beta}_1) are the coefficients on the regressors ({bf x}_i). Notice that the distribution of the potential outcomes may very well be Poisson, lognormal, or another distribution with an exponential imply.

For therapy (t_i), we observe the result

start{equation}
y_i = (1-t_i) y_{0i} + t_i y_{1i}
nonumber
finish{equation}

So we observe (y_{1i}) below the therapy ((t_{i}=1)) and (y_{0i}) when the therapy is withheld ((t_{i}=0)). The potential-outcome errors (epsilon_{0i}) and (epsilon_{1i}) are correlated with the therapy project.

The therapy (t_i) is set by regressors ({bf z}_i) in a probit regression, such that

start{equation}
t_i = {bf 1}({bf z}_i{boldsymbol psi} + u_i > 0)
nonumber
finish{equation}

the place the therapy error (u_i) is customary regular.

We deal with (t_i) as endogenous by permitting (epsilon_{0i}) and (epsilon_{1i}) to be correlated with (u_i). On this put up we’ll assume that the variances of the unobserved errors are the identical for the management and therapy group and that their correlation with (u_i) can be equal. We assume that the errors are trivariate regular with imply zero and covariance

start{equation}
left[begin{matrix}
sigma^{2} & sigma_{01} & sigma_{t} cr
sigma_{01} & sigma^{2} & sigma_{t} cr
sigma_{t} & sigma_{t} & 1
end{matrix}right]
nonumber
finish{equation}

Remedy impact

We need to determine the therapy impact of (t_i) conditional on ({bf x}_i). That is simply the distinction of the potential-outcome technique of (y_{1i}) and (y_{0i}), conditional on ({bf x}_i).

start{eqnarray*}
E(y_{1i}-y_{0i}vert{bf x}_i) &=& Eleft{E(y_{1i}-y_{0i}vert {bf x}_i, epsilon_{0i}, epsilon_{1i}) vert{bf x}_i proper} cr
&=& Eleft{exp({bf x}_i{boldsymbol beta}_1 + beta_{10}+epsilon_{1i})vert{bf x}_iright} –
Eleft{exp({bf x}_i{boldsymbol beta}_0 + beta_{00}+epsilon_{0i})vert{bf x}_iright}cr
&=& expleft({bf x}_i{boldsymbol beta}_1 + beta_{10}+frac{sigma^2}{2}proper) –
expleft({bf x}_i{boldsymbol beta}_0 + beta_{00}+frac{sigma^2}{2}proper)
cr
finish{eqnarray*}

So we are able to determine the therapy impact of (t_i) at ({bf x}_i) if we all know ({boldsymbol beta}_0), ({boldsymbol beta}_1), (beta_{00}^{star}=beta_{00}+sigma^2 / 2), and (beta_{10}^{star}=beta_{10}+sigma^2 / 2).

The ATE is the margin of the conditional therapy results over the regressors ({bf x}_i).

start{equation}
mbox{ATE} = E(y_{1i} – y_{0i}) = Eleft{E(y_{1i}-y_{0i}vert{bf x}_i)proper} nonumber
finish{equation}

Our estimator will present constant estimates of the mannequin parameters and the ATE.

Estimator

We can not simply run separate regressions for the management and therapy teams and distinction the means to estimate the therapy impact (regression adjustment estimation of the therapy impact). The potential-outcome errors (epsilon_{0i}) and (epsilon_{1i}) are correlated with (t_i), and a regression that ignores this correlation is not going to give constant level estimates.

By modeling the therapy, and utilizing this data in a mannequin for the exponential imply, we are able to account for the correlation and acquire constant level estimates. It is a two-step downside.

Not like as within the earlier posts, we can not carry out the steps independently to get level estimates. We additionally don’t have to make among the parametric assumptions that we made within the earlier posts. In our present mannequin, (y_i) may very well be Poisson, lognormal, or another distribution with an exponential imply.

We are able to specify our mannequin by way of second situations which might be glad by the parameters, quite than strict distributional assumptions that impose a chance. Second situations are anticipated values that specify the mannequin parameters by way of the true moments. The generalized technique of moments (GMM) finds parameter values which might be closest to satisfying the pattern equal of the second situations. For our two-step downside, we are able to estimate the second situations for each steps concurrently, as proven in Utilizing gmm to resolve two-step estimation issues.

The therapy regressor coefficients ({boldsymbol psi}) are recognized by the second situations

start{equation}
Eleft[{bf z}_ileft{t_i – Phileft({bf z}_i{boldsymbol psi}right)right}right] = {bf 0}
nonumber
finish{equation}

This is step one. We use the therapy project mannequin parameters to assist account for the endogeneity of the project and the result errors within the second step, the place we mannequin the exponential imply. The second situations for the second step come from a nonlinear least-squares estimator that fashions (E(y_ivert {bf x}_i,t_i, {bf z}_i)) and are given by

start{equation}
Eleft[ frac{partial Eleft(y_{i}vert {bf x}_i, t_i, z_i right)}{partial {boldsymbol beta}} left{y_i –
Eleft(y_{i}vert {bf x}_i, t_i, z_i right)
right}right]
nonumber
finish{equation}

the place

start{eqnarray*}
Eleft(y_{i}vert {bf x}_i, t_i, z_i proper) &=&
Eleft(t_i y_{1i} + (1-t_i) y_{0i} vert {bf x}_i, t_i, z_i proper) cr
&=& expleft({bf x}_i {boldsymbol beta}_{t_i} + beta_{t_i0}^{star}proper) left{frac{Phi(sigma_{t}+ {bf z}_i{boldsymbol psi)}}{Phi({bf z}_i{boldsymbol psi})}proper}^{t_i} left{frac{1-Phi(sigma_{t}+ {bf z}_i{boldsymbol psi)}}{1-Phi({bf z}_i{boldsymbol psi})}proper}^{1-t_i} cr
finish{eqnarray*}

and ({boldsymbol beta}) is

start{equation}
{boldsymbol beta} = left[begin{matrix} {boldsymbol beta}_{1} cr
{boldsymbol beta}_{0} cr
beta_{00}^{star} cr
beta_{10}^{star} cr
sigma_{t}end{matrix}right]
nonumber
finish{equation}

Extra particulars on the derivation of the conditional imply is offered within the appendix. To acquire constant level estimates, we might discover an estimate of ({boldsymbol psi}) that satisfies the pattern second situations for the primary stage. Then this estimate, (widehat{boldsymbol psi}), could be used rather than ({boldsymbol psi}) within the pattern equal of the second-stage second situations. The estimate (widehat{boldsymbol beta}) could be computed utilizing these situations. With this estimate (widehat{boldsymbol beta}), we might additionally estimate the ATE. The ATE is a operate of the parameters of the second moments and has second situation

start{equation}
Eleft{mbox{ATE} – left(
expleft({bf x}_i{boldsymbol beta}_1 + beta_{10}+frac{sigma^2}{2}proper) –
expleft({bf x}_i{boldsymbol beta}_0 + beta_{00}+frac{sigma^2}{2}proper)
proper)proper}
nonumber
finish{equation}

Our level estimates could be constant, however we would want to regulate the usual errors of the second stage and the therapy impact for the a number of steps of estimation. Sections 10.3 and a pair of.5 of Cameron and Trivedi (2013) and part 18.5 of Wooldridge (2010) describe the present mannequin and the two-step strategy. Utilizing GMM with all phases concurrently would robotically alter the usual errors. We’ll use the command gmm to estimate the primary and second phases along with the therapy impact utilizing GMM.

Estimation

We use the interactive model of gmm to estimate the parameters from simulated information. Our end result has a lognormal distribution. As within the final put up, we’ll use native macros to arrange our work.

We retailer the second equation for the therapy within the macro first. The instrument possibility for first is saved within the native macro first_inst. The second situations are calculated by multiplying the equation by the devices.


. native first (first:t - regular({t: x1 z1 z2 _cons}))

. native first_inst devices(first: x1 z1 z2)

Now, we’ll look in the mean time situations for the second stage. We’ll start with the second situations that correspond to the derivatives for the coefficients and intercepts of the exponential imply. We retailer the second equation within the macro second and the instrument possibility within the macro second_inst. As within the first case, the second situations are calculated by multiplying the equation by the devices. Notice that we specify noconstant and use ibn for t within the devices possibility. We could have separate intercepts for the therapy and management group and no marginal fixed intercept.


. native second (second:(exp(0.t*({y0:x1 x2 x3 _cons})+            
>                          1.t*({y1:x1 x2 x3 _cons}))*            
>                          cond(t,regular({sigmat}+{t:})/regular({t:}),     
>                         (regular(-{sigmat}-{t:}))/(regular(-{t:}))))*     
>                 (y- (exp(0.t*({y0:})+           
>                          1.t*({y1:}))*          
>                          cond(t,regular({sigmat}+{t:})/regular({t:}),     
>                         (regular(-{sigmat}-{t:}))/(regular(-{t:}))))))

. native second_inst devices(second: c.(x1 x2 x3)#i.t ibn.t, noconstant)

Lastly, we present the second situations that correspond to the by-product of the exponential imply for the covariance parameter and the ATE. These are saved in native macros secondt and ate. We don’t have to specify the devices for these second equations; the fixed is the instrument.


. native secondt (secondt:(exp(0.t*({y0:})+1.t*({y1:}))*                   
>                 cond(t,normalden({sigmat}+{t:})/regular({t:}),           
>                 (-normalden(-{sigmat}-{t:}))/(regular(-{t:}))))*         
>                 (y- (exp(0.t*({y0:})+                                   
>                          1.t*({y1:}))*                                  
>                          cond(t,regular({sigmat}+{t:})/regular({t:}),     
>                         (regular(-{sigmat}-{t:}))/(regular(-{t:}))))))

. native ate (ate: {ate} - (exp({y1:})-exp({y0:})))

Now, we use gmm to estimate the parameters of the exponential imply mannequin with an endogenous therapy and its ATE. Our second situations precisely determine the mannequin, so we use one-step estimation and an id preliminary weight matrix.


. matrix I = I(14)

. gmm `first' `second' `secondt' `ate', `first_inst' `second_inst' 
>         onestep winitial(I)

Step 1
Iteration 0:   GMM criterion Q(b) =  .47089834
Iteration 1:   GMM criterion Q(b) =  .01758819
Iteration 2:   GMM criterion Q(b) =  .00464735
Iteration 3:   GMM criterion Q(b) =  .00001541
Iteration 4:   GMM criterion Q(b) =  4.462e-08
Iteration 5:   GMM criterion Q(b) =  2.860e-13

notice: mannequin is strictly recognized

GMM estimation

Variety of parameters =  14
Variety of moments    =  14
Preliminary weight matrix: consumer                       Variety of obs   =     10,000

------------------------------------------------------------------------------
             |               Strong
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
t            |
          x1 |   .4878797    .016208    30.10   0.000     .4561126    .5196469
          z1 |   .3201969   .0197232    16.23   0.000     .2815401    .3588537
          z2 |  -1.023134   .0204703   -49.98   0.000    -1.063255   -.9830127
       _cons |  -.5308057   .0275083   -19.30   0.000    -.5847209   -.4768905
-------------+----------------------------------------------------------------
y0           |
          x1 |   .2897787   .0208321    13.91   0.000     .2489486    .3306088
          x2 |   .2154847   .0182694    11.79   0.000     .1796773    .2512922
          x3 |  -.2993678    .017933   -16.69   0.000    -.3345159   -.2642197
       _cons |  -.1904076   .0288861    -6.59   0.000    -.2470232   -.1337919
-------------+----------------------------------------------------------------
y1           |
          x1 |   .1828499   .0307878     5.94   0.000     .1225069    .2431928
          x2 |   .4439466   .0296223    14.99   0.000     .3858879    .5020052
          x3 |  -.5825316   .0277333   -21.00   0.000    -.6368878   -.5281753
       _cons |  -.6311437   .0308619   -20.45   0.000    -.6916319   -.5706554
-------------+----------------------------------------------------------------
     /sigmat |    .292965   .0338062     8.67   0.000     .2267061     .359224
        /ate |  -.2984529   .0242588   -12.30   0.000    -.3459992   -.2509065
------------------------------------------------------------------------------
Devices for equation first: x1 z1 z2 _cons
Devices for equation second: 0.t#c.x1 1.t#c.x1 0.t#c.x2 1.t#c.x2
    0.t#c.x3 1.t#c.x3 0.t 1.t
Devices for equation secondt: _cons
Devices for equation ate: _cons

We estimate that the ATE is (-)0.3. We’ll evaluate this estimate to the pattern distinction of (y_{1}) and (y_{0}).


. gen diff = y1 - y0

. sum diff

    Variable |        Obs        Imply    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        diff |     10,000   -.3016842    .6915832  -9.553974   5.870782

In our pattern, the common distinction of (y_{1}) and (y_{0}) can be (-)0.3.

Remaining issues

We illustrated methods to use gmm to estimate the parameters of an exponential imply mannequin with an endogenous therapy and its common therapy impact. We display methods to carry out multistep estimation in Stata when the mannequin isn’t separable, and estimation of every step requires data from the earlier step.

Within the earlier posts, we used gsem and mlexp to estimate the parameters of fashions with separable likelihoods. Within the present mannequin, as a result of the therapy is endogenous, the chance for the mannequin is not separable. We demonstrated how we are able to use gmm to estimate the parameters in these conditions.

Appendix 1

The second situations for the exponential imply correspond to the distinction between (y_i) and (E(y_ivert {bf x}_i,t_i, {bf z}_i)). The conditional imply of (y_i) relies on the conditional technique of the unobserved end result errors (epsilon_{0i}) and (epsilon_{1i}). This explicitly fashions the covariance between therapy project and the unobserved end result errors and permits us to estimate the parameters wanted to estimate conditional and common therapy results.

For (j=0,1), the conditional imply of the potential end result (y_{ji}) is
start{eqnarray*}
Eleft(y_{ji}vert {bf x}_i, t_i, z_i proper) &=&
Eleft{ Eleft(y_{ji}vert {bf x}_i, epsilon_{ji}, t_i, z_i proper)vert {bf x}_i, t_i, z_i proper} cr
&=& Eleft{expleft({bf x}_i{boldsymbol beta}_j + beta_{j0}+epsilon_{ji}proper) vert {bf x}_i, t_i, z_i proper} cr
&=&
expleft({bf x}_i{boldsymbol beta}_j + beta_{j0}proper)Eleft{expleft(epsilon_{ji}proper) vert {bf x}_i, t_i, z_i proper}
finish{eqnarray*}

As a result of (epsilon_{ji}) is correlated with (t_i) by way of the unobserved error (u_i), we have now
start{eqnarray*}
epsilon_{ji} = sigma_{t}u_i + c_{ji}
finish{eqnarray*}

the place (c_{ji}) is regular with zero imply and variance (sigma^2-sigma_{t}^2) and unbiased of (u_i).

Terza (1998) derived the conditional expectation of (exp(sigma_{t}u_i)). Utilizing his outcomes, we acquire
start{eqnarray*}
Eleft(y_{i}vert {bf x}_i, t_i, z_i proper) &=&
Eleft(t_i y_{1i} + (1-t_i) y_{0i} vert {bf x}_i, t_i, z_i proper) cr
&=& expleft({bf x}_i {boldsymbol beta}_{t_i} + beta_{t_i0}^{star}proper) left{frac{Phi(sigma_{t}+ {bf z}_i{boldsymbol psi)}}{Phi({bf z}_i{boldsymbol psi})}proper}^{t_i} left{frac{1-Phi(sigma_{t}+ {bf z}_i{boldsymbol psi)}}{1-Phi({bf z}_i{boldsymbol psi})}proper}^{1-t_i} cr
finish{eqnarray*}

Appendix 2

We simulate information from a lognormal mannequin with an endogenous therapy. The code used to provide the info is given beneath.


. set seed 113432

. set obs 10000
variety of observations (_N) was 0, now 10,000

. // Exogenous regressors
. generate x1 = rnormal()

. generate x2 = rnormal()

. generate x3 = rpoisson(1)

. // Remedy regressors
. generate z1 = ln(rchi2(4))

. generate z2 = rnormal()

. matrix corr = ( 1,  .4, .4     
>                 .4,  1, .4     
>                 .4, .4,  1)

. matrix sds = (.8, .8,1)

. drawnorm e0 e1 u, corr(corr) sd(sds)

. gen t = .5*x1 + .3*z1 - z2 -.5 + u> 0

. gen y0 = exp(.3*x1 + .2*x2 - .3*x3 + -.5 + e0)

. gen y1 = exp(.2*x1 + .4*x2 - .6*x3 + -.9 + e1)

. gen y = 0.t*y0 + 1.t*y1

The potential-outcome errors have totally different variances and correlations. We additionally use totally different coefficients for the management and therapy teams.

References

Cameron, A. C., and P. Okay. Trivedi. 2013. Regression Evaluation of Rely Information. 2nd ed. New York: Cambridge College Press.

Terza, J. V. 1998. Estimating rely information fashions with endogenous switching: Pattern choice and endogenous therapy results. Journal of Econometrics 84: 129–154.

Wooldridge, J. M. 2010. Econometric Evaluation of Cross Part and Panel Information. 2nd ed. Cambridge, MA: MIT Press.



Related Articles

Latest Articles