# Estimation Results with Stata Graphics - PowerPoint PPT Presentation

1 / 54

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….

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Estimation Results with Stata Graphics

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## 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…

• Is parental control related to adolescent delinquency?

. corrdelinqparcon

(obs=11)

| delinqparcon

-------------+------------------

delinq | 1.0000

parcon | 0.0000 1.0000

### A simple regression…

• Is parental control related to adolescent delinquency?

. reg delinqparcon

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

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

------------------------------------------------------------------------------

### Visualizing the data…

• Is parental control related to adolescent delinquency?

### Revising the model…

• Is parental control related to adolescent delinquency?

. reg delinqc.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

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.375076

c.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

-----------------------------------------------------------------------------------

### 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

### Marginal Effects

“A [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 Effects

…at the mean

• “Mean” is the average characteristic in the data

• Identify mean value and substitute into the regression equation

### Marginal Effects

Average…

• Say we’re interested in the AME for whites vs. blacks

• Imagine the first case is white, regardless of the true race

• Use other characteristics as measured

• Estimate the individual prediction

• Repeat 2 and 3 with the race as black

• The difference in predictions is individual marginal effect

• Repeat 1 through 5 for every case

• Calculate mean for entire sample

### Marginal Effects

…at representative values

• Identify profiles for individuals that have some particular meaning

### 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

### Toxoplasmosis Gondii

• Parasite whose primary host is any member of the cat family

• Transmitted by contact with feces

• Lodges into neurons

• 30 percent of world’s human population carries the parasite

• Not thought of as dangerous for healthy people

• Maybe it’s not so benign

eststom1: svy: regress sdli.toxbin##c.pir female age higradeib1.race

Number of strata = 49 Number of obs = 4169

Number 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.67

Poverty-to-income ratio (PIR) -.22*** -.32,-.12

Toxo X PIR -.22* -.42,-.03

Controls

Female .08 -.22,.38

Age .09*** .08,.11

Race

White ---

Black 1.74*** 1.39,2.09

Hispanic 2.41*** 1.79,3.04

Other 2.32*** 1.26,3.37

Constant 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?

. margins i.toxbin, at(pir=(0(1)12)) vsquish

Expression : Linear prediction, predict()

1._at : pir = 0

2._at : pir = 1

3._at : pir = 2

4._at : pir = 3

5._at : pir = 4

6._at : pir = 5

7._at : pir = 6

8._at : pir = 7

9._at : pir = 8

10._at : pir = 9

11._at : pir = 10

12._at : pir = 11

------------------------------------------------------------------------------

| 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

------------------------------------------------------------------------------

. marginsplot

### Toxoplasmosis Gondii

• At low poverty-to-income T. Gondiiis related to reduced cognitive functioning

• At high PIR T. Gondiiis related to increased cognitive functioning

. lowesssdlpir, by(toxbin)

Table 2.

Latent Toxoplasmosis and Symbol-Digit Learning Test:

-----------------------------------------------------------

b 95% CI

-----------------------------------------------------------

Toxoplasmosis (Toxo) .93** .26,1.60

Poverty-to-income ratio (PIR) -.58*** -.90,-.26

PIR^2 .04* .01,.08

Toxo X PIR -.22* -.40,-.03

Controls

Female .06 -.24,.36

Age .09*** .08,.11

Race

White ---

Black 1.66*** 1.30,2.02

Hispanic 2.33*** 1.71,2.94

Other 2.29*** 1.22,3.36

Constant 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

. lowesssdlpir, by(toxbin)

. mkspline pir1 3 pir2 = pir

. showcodingpir 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.22

Poverty-to-income ratio (PIR)

0 - 3 -.41** -.69,-.14

3 - 11 -.13 -.30,.04

Toxo X PIR interaction

0 - 3 -.44 -.95,.08

3 - 11 -.08 -.47,.32

Controls

Female .06 -.24,.36

Age .09*** .08,.11

Race

White ---

Black 1.67*** 1.31,2.04

Hispanic 2.33*** 1.72,2.94

Other 2.30*** 1.23,3.37

Constant 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

. svmatyhat0

. svmatyhat1

. svmatpiratio

. line yhat01 yhat11 piratio1

### Toxoplasmosis Gondii

• At low poverty-to-income, specifically when the ratio is less than 3, T. Gondii is related to reduced cognitive functioning

• There 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 \$20k

• A PIR of 3 would be \$60

• Mean 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)

### 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

### Graph Editor

Pros

• Don’t need to learn programming

• Saves time in short-term

Cons

• Not easily reproducible

• Loses time in long-run

### resources

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