Translation of examples in Stata tip 87 to Stata version 10 or less

Maarten L. Buis

Abstract

The examples in the article Stata tip 87: Interpretation of interactions in non-linear models use two features that are new in Stata 11, factor variables and the margins command. However the logic of the argument in this article also applies to earlier versions of Stata (and other statistical packages). Below is Stata code for the same examples that can be run in earlier versions of Stata.

. sysuse nlsw88, clear (NLSW, 1988 extract)

. gen byte high_occ = occupation < 3 if occupation < . (9 missing values generated)

. gen byte black = race == 2 if race < .

. drop if race == 3 (26 observations deleted)

. gen byte baseline = 1

. . // manually create the interection term . gen blXcoll = black*collgrad

. . logit high_occ black collgrad blXcoll baseline, or nocons nolog

Logistic regression Number of obs = 2211 Wald chi2(4) = 504.62 Log likelihood = -1199.4399 Prob > chi2 = 0.0000

------------------------------------------------------------------------------ high_occ | Odds Ratio Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- black | .4194072 .0655069 -5.56 0.000 .3088072 .5696188 collgrad | 2.465411 .293568 7.58 0.000 1.952238 3.113478 blXcoll | 1.479715 .4132536 1.40 0.161 .8559637 2.558003 baseline | .3220524 .0215596 -16.93 0.000 .2824512 .3672059 ------------------------------------------------------------------------------

. . // use -adjust- instead of -margins- . adjust, by(collgrad black) exp

------------------------------------------------------------------------------- Dependent variable: high_occ Equation: high_occ Command: logit Variables left as is: baseline, blXcoll -------------------------------------------------------------------------------

----------------------------------- | black college graduate | 0 1 -----------------+----------------- not college grad | .322052 .135071 college grad | .793991 .492754 ----------------------------------- Key: exp(xb)

. . // -adjust- cannot leave its results behind as if it where an . // estimation command, so we need to compute the expected odds . // and their differences using -nlcom- instead of leaving the . // expected odds behind and use -lincom- to compute the differences . . nlcom ( white: exp(_b[baseline]+_b[collgrad] ) - /// > exp(_b[baseline] ) ) /// > ( black: exp(_b[baseline]+_b[black]+_b[collgrad]+_b[blXcoll]) - /// > exp(_b[baseline]+_b[black]) ) /// >

white: exp(_b[baseline]+_b[collgrad] ) - > exp(_b[baseline] ) black: exp(_b[baseline]+_b[black]+_b[collgrad]+_b[blXcoll]) - > exp(_b[baseline]+_b[black])

------------------------------------------------------------------------------ high_occ | Coef. Std. Err. z P>|z| [95% Conf. Interval] -------------+---------------------------------------------------------------- white | .471939 .081106 5.82 0.000 .3129742 .6309038 black | .3576825 .1049933 3.41 0.001 .1518994 .5634656 ------------------------------------------------------------------------------

[do-file]