Estimation Results with Stata Graphics

54
ESTIMATION RESULTS WITH STATA GRAPHICS LANCE ERICKSON

description

Estimation Results with Stata Graphics. Lance Erickson. Outline. Why we need graphics Marginal effects Marginal effects at the means Average marginal effects Marginal effects at representative values Walking through an example Programming Graph editor. A simple correlation…. - PowerPoint PPT Presentation

Transcript of Estimation Results with Stata Graphics

Estimation Results with Stata Graphics

Estimation Results with Stata GraphicsLance EricksonOutlineWhy we need graphicsMarginal effectsMarginal effects at the meansAverage marginal effectsMarginal effects at representative valuesWalking through an exampleProgrammingGraph editor

2A simple correlationIs parental control related to adolescent delinquency?. corr delinq parcon(obs=11)

| delinq parcon-------------+------------------ delinq | 1.0000 parcon | 0.0000 1.0000clearinput parcon delinq1 101.2 81.6 62.0 42.6 23.5 14.4 25.0 45.4 65.8 86 10end

corr delinq parcon

3A simple regressionIs parental control related to adolescent delinquency?. reg delinq parcon

Source | SS df MS Number of obs = 11-------------+------------------------------ F( 1, 9) = 0.00 Model | 1.4211e-14 1 1.4211e-14 Prob > F = 1.0000 Residual | 102.727273 9 11.4141414 R-squared = 0.0000-------------+------------------------------ Adj R-squared = -0.1111 Total | 102.727273 10 10.2727273 Root MSE = 3.3785

------------------------------------------------------------------------------ delinq | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+---------------------------------------------------------------- parcon | 1.76e-08 .5598242 0.00 1.000 -1.26641 1.26641 _cons | 5.545454 2.208356 2.51 0.033 .5498056 10.5411------------------------------------------------------------------------------reg delinq parcon

4Visualizing the dataIs parental control related to adolescent delinquency?

sc delinq parcon, ylabel(, angle(0)) msize(large) ytitle(Adolescent Delinquency) xtitle(Parental Control) ysize(4) xsize(5.5) scheme(s1mono)

5Revising the modelIs parental control related to adolescent delinquency?. reg delinq c.parcon##c.parcon

Source | SS df MS Number of obs = 11-------------+------------------------------ F( 2, 8) = 930.87 Model | 102.287737 2 51.1438687 Prob > F = 0.0000 Residual | .439535405 8 .054941926 R-squared = 0.9957-------------+------------------------------ Adj R-squared = 0.9947 Total | 102.727273 10 10.2727273 Root MSE = .2344

----------------------------------------------------------------------------------- delinq | Coef. Std. Err. t P>|t| [95% Conf. Interval]------------------+---------------------------------------------------------------- parcon | -9.912351 .2329897 -42.54 0.000 -10.44963 -9.375076c.parcon#c.parcon | 1.41605 .0328185 43.15 0.000 1.340371 1.49173 _cons | 18.20366 .330967 55.00 0.000 17.44044 18.96687-----------------------------------------------------------------------------------reg delinq c.parcon##c.parcon

6OutlineWhy we need graphicsMarginal effectsMarginal effects at the meansAverage marginal effectsMarginal effects at representative valuesWalking through an exampleProgrammingGraph editor

7Marginal EffectsA [marginal effect], or partial effect, most often measures the effect on the conditional mean of y of a change in one of the regressors, say xk. In the linear regression model, the [marginal effect] equals the relevant slope coefficient, greatly simplifying analysis. For nonlinear models, this is no longer the case, leading to remarkably many different methods for calculating [marginal effects].If x changes by one unit, how would y change?Marginal Effectsat the meanMean is the average characteristic in the dataIdentify mean value and substitute into the regression equation

Marginal EffectsAverageSay were interested in the AME for whites vs. blacksImagine the first case is white, regardless of the true raceUse other characteristics as measuredEstimate the individual predictionRepeat 2 and 3 with the race as blackThe difference in predictions is individual marginal effectRepeat 1 through 5 for every caseCalculate mean for entire sample

Marginal Effectsat representative valuesIdentify profiles for individuals that have some particular meaningOutlineWhy we need graphicsMarginal effectsMarginal effects at the meansAverage marginal effectsMarginal effects at representative valuesWalking through an exampleProgramming Graph Editor

12Toxoplasmosis GondiiParasite whose primary host is any member of the cat familyTransmitted by contact with fecesLodges into neurons30 percent of worlds human population carries the parasiteNot thought of as dangerous for healthy people

Maybe its not so benigneststo m1: svy: regress sdl i.toxbin##c.pir female age higrade ib1.race

Number of strata = 49 Number of obs = 4169Number of PSUs = 98 Population size = 109225249 Design df = 49 F( 9, 41) = 157.93 Prob > F = 0.0000 R-squared = 0.2657

------------------------------------------------------------------------------ | Linearized sdl | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+---------------------------------------------------------------- 1.toxbin | .9756481 .3447252 2.83 0.007 .282897 1.668399 pir | -.2212445 .0501302 -4.41 0.000 -.321985 -.1205041 |toxbin#c.pir | 1 | -.2222757 .0970269 -2.29 0.026 -.4172585 -.0272929 | female | .0780064 .1505963 0.52 0.607 -.2246282 .380641 age | .0936083 .0070641 13.25 0.000 .0794125 .1078042 higrade | -.5190588 .0388779 -13.35 0.000 -.597187 -.4409307 | race | Black | 1.741903 .1750276 9.95 0.000 1.390172 2.093634 Hispanic | 2.414574 .3088713 7.82 0.000 1.793874 3.035274 Other | 2.315488 .5264093 4.40 0.000 1.257629 3.373347 | _cons | 7.715189 .6056571 12.74 0.000 6.498076 8.932303------------------------------------------------------------------------------estout m1, cells("b(star fmt(2)) ci") stats(N r2, fmt(0 2) label(N "R squared")) nolz ///collabels(b "95% CI") mlabels(none) ///prehead("Table 1.""Latent Toxoplasmosis and Symbol-Digit Learning Test:" /// "Poverty-to-income Ratio as Linear") ///drop(0b.toxbin 0b.toxbin#co.pir 1b.race) ///order(1.toxbin pir 1.toxbin#c.pir Controls female age higrade race) ///varlabels(1.toxbin "Toxoplasmosis (Toxo)" pir "Poverty-to-income ratio (PIR)" /// 1.toxbin#c.pir "Toxo X PIR" female " Female" age " Age" /// higrade " Highest grade achieved" race " Race" 2.race " Black" /// 3.race " Hispanic" 4.race " Other" _cons "Constant") ///refcat(2.race " White", label(---)) ///postfoot("Note:""* p < .05. ** p < .01. *** p < 001.""Source: NHANES III.") ///varwidth(30)Table 1.Latent Toxoplasmosis and Symbol-Digit Learning Test:Poverty-to-income Ratio as Linear----------------------------------------------------------- b 95% CI-----------------------------------------------------------Toxoplasmosis (Toxo) .98** .28,1.67Poverty-to-income ratio (PIR) -.22*** -.32,-.12Toxo X PIR -.22* -.42,-.03Controls Female .08 -.22,.38 Age .09*** .08,.11 Highest grade achieved -.52*** -.60,-.44 Race White --- Black 1.74*** 1.39,2.09 Hispanic 2.41*** 1.79,3.04 Other 2.32*** 1.26,3.37Constant 7.72*** 6.50,8.93-----------------------------------------------------------N 4169 R squared .27 -----------------------------------------------------------Note:* p < .05. ** p < .01. *** p < 001.Source: NHANES III.

What does the relationship between SDL and toxoplasmosis look like at different levels of poverty-to-income?------------------------------------------------------------------------------ | Delta-method | Margin Std. Err. t P>|t| [95% Conf. Interval]-------------+---------------------------------------------------------------- _at#toxbin | 1 0 | 5.017781 .1803758 27.82 0.000 4.655302 5.380259 1 1 | 5.993429 .3785632 15.83 0.000 5.232678 6.75418 2 0 | 4.796536 .144264 33.25 0.000 4.506627 5.086445 2 1 | 5.549909 .2829059 19.62 0.000 4.981388 6.118429 3 0 | 4.575292 .118806 38.51 0.000 4.336542 4.814041 3 1 | 5.106388 .2005721 25.46 0.000 4.703324 5.509453 4 0 | 4.354047 .1115513 39.03 0.000 4.129876 4.578218 4 1 | 4.662868 .154565 30.17 0.000 4.352258 4.973478 5 0 | 4.132803 .1256924 32.88 0.000 3.880214 4.385391 5 1 | 4.219348 .1761228 23.96 0.000 3.865416 4.57328 6 0 | 3.911558 .1554978 25.16 0.000 3.599073 4.224043 6 1 | 3.775828 .2482254 15.21 0.000 3.277 4.274655 7 0 | 3.690313 .1938727 19.03 0.000 3.300712 4.079915 7 1 | 3.332307 .3401179 9.80 0.000 2.648815 4.0158 8 0 | 3.469069 .2366849 14.66 0.000 2.993433 3.944705 8 1 | 2.888787 .4395592 6.57 0.000 2.00546 3.772115 9 0 | 3.247824 .2819202 11.52 0.000 2.681285 3.814364 9 1 | 2.445267 .5424133 4.51 0.000 1.355247 3.535287 10 0 | 3.02658 .3285792 9.21 0.000 2.366275 3.686884 10 1 | 2.001747 .6470546 3.09 0.003 .7014417 3.302052 11 0 | 2.805335 .3761325 7.46 0.000 2.049469 3.561202 11 1 | 1.558227 .7527383 2.07 0.044 .0455422 3.070911 12 0 | 2.584091 .4242795 6.09 0.000 1.731469 3.436712 12 1 | 1.114706 .8590798 1.30 0.201 -.6116792 2.841092------------------------------------------------------------------------------. margins i.toxbin, at(pir=(0(1)12)) vsquish

Expression : Linear prediction, predict()1._at : pir = 02._at : pir = 13._at : pir = 24._at : pir = 35._at : pir = 46._at : pir = 57._at : pir = 68._at : pir = 79._at : pir = 810._at : pir = 911._at : pir = 1012._at : pir = 11

. marginsplot

Toxoplasmosis GondiiAt low poverty-to-income T. Gondii is related to reduced cognitive functioningAt high PIR T. Gondii is related to increased cognitive functioning. lowess sdl pir, by(toxbin)

Table 2.Latent Toxoplasmosis and Symbol-Digit Learning Test:Poverty-to-income Ratio as Quadratic----------------------------------------------------------- b 95% CI-----------------------------------------------------------Toxoplasmosis (Toxo) .93** .26,1.60Poverty-to-income ratio (PIR) -.58*** -.90,-.26PIR^2 .04* .01,.08Toxo X PIR -.22* -.40,-.03Controls Female .06 -.24,.36 Age .09*** .08,.11 Highest grade achieved -.51*** -.59,-.43 Race White --- Black 1.66*** 1.30,2.02 Hispanic 2.33*** 1.71,2.94 Other 2.29*** 1.22,3.36Constant 8.12*** 6.80,9.44-----------------------------------------------------------N 4169 R squared .27 -----------------------------------------------------------Note:* p < .05. ** p < .01. *** p < 001.Source: NHANES III.

What does the relationship between SDL and toxoplasmosis look like at different levels of poverty-to-income?. marginsplot

. lowess sdl pir, by(toxbin)

. mkspline pir1 3 pir2 = pir. showcoding pir pir1 pir2

+---------------------+ | pir pir1 pir2 | |---------------------| | 0 0 0 | | 1 1 0 | | 2 2 0 | | 3 3 0 | | 4 3 1 | | 5 3 2 | | 6 3 3 | | 7 3 4 | | 8 3 5 | | 9 3 6 | | 10 3 7 | +---------------------+Table 3.Latent Toxoplasmosis and Symbol-Digit Learning Test:Poverty-to-income Ratio as Piecewise----------------------------------------------------------- b 95% CI-----------------------------------------------------------Toxoplasmosis (Toxo) 1.32** .42,2.22Poverty-to-income ratio (PIR) 0 - 3 -.41** -.69,-.14 3 - 11 -.13 -.30,.04Toxo X PIR interaction 0 - 3 -.44 -.95,.08 3 - 11 -.08 -.47,.32Controls Female .06 -.24,.36 Age .09*** .08,.11 Highest grade achieved -.51*** -.59,-.43 Race White --- Black 1.67*** 1.31,2.04 Hispanic 2.33*** 1.72,2.94 Other 2.30*** 1.23,3.37Constant 7.96*** 6.68,9.25-----------------------------------------------------------N 4169 R squared .27 -----------------------------------------------------------Note:* p < .05. ** p < .01. *** p < 001.Source: NHANES III.What does the relationship between SDL and toxoplasmosis look like at different levels of poverty-to-income?

. margins, at(toxbin=0 pir1=0 pir2=0) ///at(toxbin=0 pir1=1 pir2=0) ///at(toxbin=0 pir1=2 pir2=0) ///at(toxbin=0 pir1=3 pir2=0) ///at(toxbin=0 pir1=3 pir2=1) ///at(toxbin=0 pir1=3 pir2=2) ///at(toxbin=0 pir1=3 pir2=3) ///at(toxbin=0 pir1=3 pir2=4) ///at(toxbin=0 pir1=3 pir2=5) ///at(toxbin=0 pir1=3 pir2=6) ///at(toxbin=0 pir1=3 pir2=7) ///at(toxbin=0 pir1=3 pir2=8) vsquish. mat yhat0 = r(b)'. margins, at(toxbin=1 pir1=0 pir2=0) ///at(toxbin=1 pir1=1 pir2=0) ///at(toxbin=1 pir1=2 pir2=0) ///at(toxbin=1 pir1=3 pir2=0) ///at(toxbin=1 pir1=3 pir2=1) ///at(toxbin=1 pir1=3 pir2=2) ///at(toxbin=1 pir1=3 pir2=3) ///at(toxbin=1 pir1=3 pir2=4) ///at(toxbin=1 pir1=3 pir2=5) ///at(toxbin=1 pir1=3 pir2=6) ///at(toxbin=1 pir1=3 pir2=7) ///at(toxbin=1 pir1=3 pir2=8) vsquish. mat yhat1 = r(b)'. mat piratio = 0\1\2\3\4\5\6\7\8\9\10\11. svmat yhat0. svmat yhat1. svmat piratio. line yhat01 yhat11 piratio1

Toxoplasmosis GondiiAt low poverty-to-income, specifically when the ratio is less than 3, T. Gondii is related to reduced cognitive functioningThere is no relationship between T. Gondii and cognitive functioning among individuals whose PIR is greater than 3

For a family of 4, the poverty ratio is about $20kA PIR of 3 would be $60Mean household income in US is lower; Median is greater

. line yhat01 yhat11 piratio1. line yhat01 yhat11 piratio1

line yhat01 yhat11 piratio1

line yhat01 yhat11 piratio1, xsize(7) ysize(5) scheme(s1mono) ///title("Figure 4.""Model-based Predictions of the Symbol-Digit Learning Test:" /// "Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise", /// j(left) size(medsmall) span) ///ytitle(Serial Digit Learning Test) ylabel(0(1)7, angle(0)) ///xtitle(Poverty-to-income Ratio) xlabel(0(1)11) ///lpattern(dash solid) lcolor(black black) ///legend(title(Latent Toxoplasmosis, size(small)) order(1 "Negative" 2 "Positive")) ///note("Note: N = 4038""Source: NHANES III", span)OutlineWhy we need graphicsMarginal effectsMarginal effects at the meansAverage marginal effectsMarginal effects at representative valuesWalking through an exampleProgramming Graph editor

52Graph EditorProsDont need to learn programmingSaves time in short-termConsNot easily reproducibleLoses time in long-run

resources

http://www.stata.com/statalist/