.- help for ^-margfx-^ .- Computing mean marginal effects with nonlinear models ----------------------------------------------------- ^margfx^ varlist [^if^ exp] [^in^ range]^, [^binary^([binary vars]) ^contin^([continuous vars]) ^quietly^ ^model^([estimation model to use]) ^done^ ^rob^ust ^clus^ter([cluster varname]) ^base^line([replace-friendly syntax yielding baseline condition for dummy-variable marginal effects])^] Both aweights and fweights are allowed. ^-margfx-^ currently supports probit and logit models (see below). ^-margfx-^ shares the features of all estimation commands; see help @est@. ^-margfx-^, typed without arguments, will use previous estimation results, if possible (see below). To reset problem-size limits, see help @matsize@. Description ----------- 1. Estimated effects -------------------- ^-margfx-^ estimates the mean (over a chosen sample) marginal effect of a RHS variable on the probability that the observed outcome for the LHS is 1. For a detailed description of the underlying math, see the help file ^margfx-math.hlp^. 2. Estimated Covariance Matrix ------------------------------ The estimated variance is calculated using the delta method. The resulting matrix is an asymptotically valid first-order approximation to the asymptotic covariance matrix for the marginal effects. Note that this means that a) Unlike ^-dprobit-^, ^-margfx-^ reports the estimated standard error for the marginal effect, rather than for the underlying coefficient. In practice the estimated standard errors are generally similar for the marginal effect and the coefficient. However, the approach used by ^-margfx-^ is the correct one, and in cases with a great deal of covariance across coefficients differences may arise. b) Estimates are generated for the off-diagonal elements of the variance matrix, so that hypotheses regarding the relationship of multiple marginal effects may be jointly examined using Stata's ^-test-^ and related commands. Equally importantly, the full covariance matrix is available for use in specification testing, e.g. using ^-hausman-^ to test whether the estimated marginal effects differ significantly across specifications. This facility cannot be implemented using ^-dprobit-^. For more on the delta method for estimating the covariance matrix of nonlinear functions of estimated coefficients, see William H. Greene's "Econometric Analysis", which provides a detailed treatment. For a more detailed description of the underlying math, see the help file ^margfx-math.hlp^. Execution and Options --------------------- There are multiple ways to use ^-margfx-^. The first way is "free standing". An example of a free standing approach is: . margfx mig7580, binary(dummy) contin(age oldest) model(probit) Running probit of depvar mig7580 on rhs continuous variables age oldest and rhs binary variables dummy Iteration 0: Log Likelihood =-2353.5841 Iteration 1: Log Likelihood =-2335.6748 Iteration 2: Log Likelihood = -2335.615 Iteration 3: Log Likelihood = -2335.615 Probit Estimates Number of obs = 9055 chi2(3) = 35.94 Prob > chi2 = 0.0000 Log Likelihood = -2335.615 Pseudo R2 = 0.0076 ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .0253363 .0797116 0.318 0.751 -.1308956 .1815682 age | -.0078052 .0046901 -1.664 0.096 -.0169977 .0013872 oldest | -.0249115 .0118544 -2.101 0.036 -.0481456 -.0016774 _cons | -.9706921 .1218773 -7.965 0.000 -1.209567 -.731817 ------------------------------------------------------------------------------ Mean of marginal effects, Number of obs = 9055 observation-by-observation ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .0034818 .0109978 0.317 0.752 -.0180735 .0250371 age | -.0010685 .0006424 -1.663 0.096 -.0023275 .0001906 oldest | -.0034101 .001624 -2.100 0.036 -.0065931 -.0002271 ------------------------------------------------------------------------------ ==> The option ^model^ is used to specify that a ^-probit-^ model is to be estimated. Specifying ^-logit-^ instead does the expected. You can suppress all output of the chosen model by using ^-margfx-^'s ^-quietly-^ option. ==> The ^varlist^ includes only one variable, the dependent variable "^mig7580^". ==> The options "^binary^" and "^contin^" respectively specify binary and continuous variables for which you want coefficient estimates. Note: with the given syntax, if you specify a variable as binary and it is not, ^-margfx-^ will still behave as if it is binary, calculating the binary marginal effect described above. If your "^contin^" list includes a variable that is actually binary, ^-margfx-^ will still calculate the continuous treatment effect described above. An alternative approach is to first run the model you want using Stata's native command and then run ^-margfx-^, using the ^-done-^ option to let ^-margfx-^ know to get the estimates from Stata's internal system matrices: . probit mig7580 age oldest dummy Iteration 0: Log Likelihood =-2353.5841 Iteration 1: Log Likelihood =-2335.6748 Iteration 2: Log Likelihood = -2335.615 Iteration 3: Log Likelihood = -2335.615 Probit Estimates Number of obs = 9055 chi2(3) = 35.94 Prob > chi2 = 0.0000 Log Likelihood = -2335.615 Pseudo R2 = 0.0076 ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- age | -.0078052 .0046901 -1.664 0.096 -.0169977 .0013872 oldest | -.0249115 .0118544 -2.101 0.036 -.0481456 -.0016774 dummy | .0253363 .0797116 0.318 0.751 -.1308956 .1815682 _cons | -.9706921 .1218773 -7.965 0.000 -1.209567 -.731817 ------------------------------------------------------------------------------ . margfx mig7580, binary(dummy) contin(age oldest) done quietly Using results from probit of depvar mig7580 on rhs continuous variables age oldest and rhs binary variables dummy Mean of marginal effects, Number of obs = 9055 observation-by-observation ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .0034818 .0109978 0.317 0.752 -.0180735 .0250371 age | -.0010685 .0006424 -1.663 0.096 -.0023275 .0001906 oldest | -.0034101 .001624 -2.100 0.036 -.0065931 -.0002271 ------------------------------------------------------------------------------ ==> Note that without the "quietly" option, ^-margfx-^ would have regurgitated the existing estimates for us. ==> Note also that ^-margfx-^ has reordered the reported effects in the table of output so that all binary variables come first. In general, since we had just estimated the underlying model, there is a more convenient way to run ^-margfx-^. When no ^-varlist-^ is specified, ^-margfx-^ assumes that the estimates to use are already stored internally. Thus we could run ^-margfx-^ as follows: . quietly probit mig7580 age oldest dummy . margfx, quiet Using results from probit of depvar mig7580 on rhs continuous variables age oldest and rhs binary variables dummy Mean of marginal effects, Number of obs = 9055 observation-by-observation ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .0034818 .0109978 0.317 0.752 -.0180735 .0250371 age | -.0010685 .0006424 -1.663 0.096 -.0023275 .0001906 oldest | -.0034101 .001624 -2.100 0.036 -.0065931 -.0002271 ------------------------------------------------------------------------------ One advantage of first running the ^-probit-^ and then running ^-margfx-^ is that we can estimate the model for an entire population and then generate estimated marginal effects for interesting subsamples: . quietly probit mig7580 age oldest dummy . margfx if age > 30, quiet Using results from probit of depvar mig7580 on rhs continuous variables age oldest and rhs binary variables dummy Mean of marginal effects, Number of obs = 4277 observation-by-observation ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .002951 .0092058 0.321 0.749 -.0150922 .0209941 age | -.000918 .0005388 -1.704 0.088 -.0019741 .0001381 oldest | -.0029301 .0013948 -2.101 0.036 -.0056639 -.0001962 ------------------------------------------------------------------------------ Note that had we instead run only ^-margfx-^, with a "model(probit)" declaration, our estimated marginal effects would not only have been calculated over only the restricted sample, they would have been based on ^-probit-^ estimates generated for only that subsample as well: . margfx mig7580 if age > 30, binary(dummy) contin(age oldest) model(probit) Running probit of depvar mig7580 on rhs continuous variables age oldest and rhs binary variables dummy Iteration 0: Log Likelihood =-949.65191 Iteration 1: Log Likelihood =-947.14454 Iteration 2: Log Likelihood =-947.14121 Iteration 3: Log Likelihood =-947.14121 Probit Estimates Number of obs = 4277 chi2(3) = 5.02 Prob > chi2 = 0.1702 Log Likelihood = -947.14121 Pseudo R2 = 0.0026 ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .1997018 .1272084 1.570 0.116 -.0496221 .4490258 age | -.0044688 .0063156 -0.708 0.479 -.0168471 .0079095 oldest | -.0369913 .0188199 -1.966 0.049 -.0738776 -.0001051 _cons | -1.069741 .2614336 -4.092 0.000 -1.582142 -.5573409 ------------------------------------------------------------------------------ Mean of marginal effects, Number of obs = 4277 observation-by-observation ------------------------------------------------------------------------------ mig7580 | Coef. Std. Err. z P>|z| [95% Conf. Interval] ---------+-------------------------------------------------------------------- dummy | .0214544 .0126936 1.690 0.091 -.0034245 .0463334 age | -.0005187 .0007332 -0.707 0.479 -.0019558 .0009185 oldest | -.0042932 .0021898 -1.961 0.050 -.0085851 -1.34e-06 ------------------------------------------------------------------------------ Lastly, suppose we now want to test whether 3 times the marginal effect for "age" is significantly different from the effect for "dummy" (never mind why): . test 3*age = dummy ( 1) - dummy + 3.0 age = 0.0 chi2( 1) = 3.29 Prob > chi2 = 0.0697 Compare this result to the (inappropriate) one reported by ^-dprobit-^: . quietly dprobit mig7580 age oldest dummy if age > 30 . test 3*age = dummy ( 1) 3.0 age - dummy = 0.0 chi2( 1) = 2.82 Prob > chi2 = 0.0931 ^-margfx-^ will use Huber/White/Sandwich estimates of the covariance matrix if the ^-robust-^ option is specified. Specifying the ^-cluster-^ option, with a clustering variable inside the parentheses, allows relaxation of error independence within-cluster; this option automatically implies ^-robust-^. If you have already estimated the underlying model when you invoke ^-margfx-^, ^-margfx-^ will let you know when the model was estimated with robust and/or cluster, even if you don't specify these options. If you specify either option, but the underlying model was estimated without them, ^-margfx-^ will exit and inform you why; this feature prevents you from wrongly thinking you have robust estimates when you don't. The ^-baseline-^ option allows you to specify a set of baseline conditions that are supposed to prevail when estimating binary marginal effects. Consider a situation in which there are two separate dummy variables, D1 and D2, where each represents a different, mutually exclusive "reform" condition. This means that D1==1 ==> D2==0 and D2==1 ==> D1==0, but neither converse holds (otherwise there would be perfect multicollinearity). For example, suppose that in the baseline state, no unions are allowed, while in the D1==1 state, unions are allowed but organizers can be fired by corporate executives. Finally, in the D2==1 state, unions are allowed and organizers can sue for significant damages if fired. If we estimate separate coefficients for D1 and D2, we probably want to know the marginal effects of having either policy, ^relative to the baseline of having neither^ (we might also want the marginal effects of moving to D2 from D1, something that can be gotten with the same approach I'm discussing here). To do this, use the following syntax: margfx depvar [if condn] [in condn], binary(D1 D2) contin([list of continuous vars]) baseline( D1=0 D2=0) [If you don't know anything about programming, or programming in Stata, ignore the next little bit.] The resulting `baseline' local macro will be parsed on whitespace, with each token then tossed into a loop of the following form: foreach token in `baseline' { replace `token' } This is what allows you to use any replace-friendly syntax here (although at the moment you can't add if/in conditions, since the parsing of `baseline' is done on whitespace; I may fix this one day). Saved Results ------------- ^-margfx-^ reports saved results in the following global macros: S_E_nobs : Number of observations used S_E_if : The "if" statement, if there is one S_E_in : The "in" condition, if there is one S_E_mod : The underlying model used to estimate the parameters S_E_cmd : The command name just used, "margfx" S_E_depv : The dependent variable of the underlying model S_E_bin : A list of the binary RHS variables S_E_con : A list of the continuous RHS variables S_E_cvn : The name of the clustering variable, if there is one S_E_vce : Nothing, or "robust" if the variance matrix is robust S_E_ll : The value of the log-likelihood statistic for the model S_E_mdf : The number of chi-squared degrees of freedom S_E_chi2 : The chi-squared statistic S_E_cn : Nothing, or the number of clusters Also see -------- Manual: ^[U] 26 Estimation and post-estimation commands^ ^[U] 35 Overview of model estimation^ ^[R] probit^ ^[R] logit^ ^[R] matrix get^ On-line: help for @est@; @probit@; @logit@; @test@; @matrix get@;