### Estimation Results with Stata Graphics

```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?
. corr delinq parcon
(obs=11)
|
delinq
parcon
-------------+-----------------delinq |
1.0000
parcon |
0.0000
1.0000
A SIMPLE REGRESSION…
• Is parental control related to adolescent delinquency?
. reg delinq parcon
Source |
SS
df
MS
-------------+-----------------------------Model | 1.4211e-14
1 1.4211e-14
Residual | 102.727273
9 11.4141414
-------------+-----------------------------Total | 102.727273
10 10.2727273
Number of obs
F( 1,
9)
Prob > F
R-squared
Root MSE
=
11
=
0.00
= 1.0000
= 0.0000
= -0.1111
= 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?
10
8
6
4
2
0
1
2
3
4
Parental Control
5
6
REVISING THE MODEL…
• Is parental control related to adolescent delinquency?
. reg delinq c.parcon##c.parcon
Source |
SS
df
MS
-------------+-----------------------------Model | 102.287737
2 51.1438687
Residual | .439535405
8 .054941926
-------------+-----------------------------Total | 102.727273
10 10.2727273
Number of obs
F( 2,
8)
Prob > F
R-squared
Root MSE
=
=
=
=
=
=
11
930.87
0.0000
0.9957
0.9947
.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
1. Imagine the first case is white, regardless of the true race
2. Use other characteristics as measured
3. Estimate the individual prediction
4. Repeat 2 and 3 with the race as black
5. The difference in predictions is individual marginal effect
6. Repeat 1 through 5 for every case
7. 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
eststo m1: svy: regress sdl i.toxbin##c.pir female age higrade ib1.race
Number of strata
Number of PSUs
=
=
49
98
Number of obs
Population size
Design df
F(
9,
41)
Prob > F
R-squared
=
=
=
=
=
=
4169
109225249
49
157.93
0.0000
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
.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" ///
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
-.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.37
Constant
7.72***
6.50,8.93
----------------------------------------------------------N
4169
R squared
.27
----------------------------------------------------------Note:
* p < .05. ** p < .01. *** p < 001.
Source: NHANES III.
SDL  7 . 72  . 98 toxo  . 22 pir  . 22 toxo  pir
 . 08 female  . 09 age  . 52 grade
 1 . 74 black  2 . 41 hispanic  2 . 32 other
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 at(pir=(0(1)12))
5.086445
.
margins i.toxbin,
vsquish
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
Expression
: Linear prediction,
predict()
3 1 |
5.106388
.2005721
25.46
0.000
4.703324
5.509453
1._at
: pir
=
0
4 0 |
4.354047
.1115513
39.03
0.000
4.129876
4.578218 =
2._at
: pir
1
4 1 |
4.662868
.154565
30.17
0.000
4.352258
4.973478 =
3._at
: pir
2
5 0 |
4.132803
.1256924
32.88
0.000
3.880214
4.385391
4._at
: pir
=
3
5 1 |
4.219348
.1761228
23.96
0.000
3.865416
4.57328 =
5._at
: pir
4
6 0 |
3.911558
.1554978
25.16
0.000
3.599073
4.224043 =
6._at
: pir
5
6 1 |
3.775828
.2482254
15.21
0.000
3.277
4.274655 =
7._at
:
pir
6
7 0 |
3.690313
.1938727
19.03
0.000
3.300712
4.079915
8._at
: pir
=
7
7 1 |
3.332307
.3401179
9.80
0.000
2.648815
4.0158 =
9._at
: pir
8
8 0 |
3.469069
.2366849
14.66
0.000
2.993433
3.944705 =
10._at
: pir
9
8 1 |
2.888787
.4395592
6.57
0.000
2.00546
3.772115
11._at
: pir
=
10
9 0 |
3.247824
.2819202
11.52
0.000
2.681285
3.814364 =
12._at
: pir
11
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
Figure 1.
Model-based Predictions of the Symbol-Digit Learning Test:
The Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-Income Ratio
8
Latent Toxoplasmosis
Negative
Note: N = 4038
Source: NHANES III
Positive
9
10
11
Toxoplasmosis Gondii
• At low poverty-to-income T. Gondii is related to reduced
cognitive functioning
• At high PIR T. Gondii is related to increased cognitive
functioning
. lowess sdl pir, by(toxbin)
Figure 2.
Lowess Curve of Serial-Digit Learning Test and Poverty-to-Income Ratio
by Toxoplasma Status
Toxoplasma Negative
Toxoplasma Positive
15
10
5
0
0
1
2
3
4
5
6
7
8
9 10 11
0
1
2
Povert-to-Income Ratio
3
4
5
6
7
8
9 10 11
Table 2.
Latent Toxoplasmosis and Symbol-Digit Learning Test:
Poverty-to-income Ratio as Quadratic
----------------------------------------------------------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
-.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.36
Constant
8.12***
6.80,9.44
----------------------------------------------------------N
4169
R squared
.27
----------------------------------------------------------Note:
* p < .05. ** p < .01. *** p < 001.
Source: NHANES III.
SDL  8 . 12  . 93 toxo  . 58 pir  . 04 pir  . 22 toxo  pir
 . 06 female  . 09 age  . 51 grade
2
 1 . 66 black  2 . 33 hispanic  2 . 29 other
What does the relationship between SDL and toxoplasmosis
look like at different levels of poverty-to-income?
. marginsplot
Figure 3.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Quadratic
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-Income Ratio
8
Latent Toxoplasmosis
Negative
Note: N = 4038
Source: NHANES III
Positive
9
10
11
. lowess sdl pir, by(toxbin)
Figure 1.
Lowess Curve of Serial-Digit Learning Test and Poverty-to-Income Ratio
by Toxoplasma Status
Toxoplasma Negative
Toxoplasma Positive
15
10
5
0
0
1
2
3
4
5
6
7
8
9 10 11
0
1
2
Povert-to-Income Ratio
3
4
5
6
7
8
9 10 11
. 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.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
-.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.37
Constant
7.96***
6.68,9.25
----------------------------------------------------------N
4169
R squared
.27
----------------------------------------------------------Note:
* p < .05. ** p < .01. *** p < 001.
Source: NHANES III.
SDL  7 . 96  1 . 32 toxo  . 41 pir 0  3  . 13 pir 3 11
 . 44 toxo  pir 0  3  . 08 toxo  pir 3 11
 . 06 female  . 09 age  . 51 grade
 1 . 67 black  2 . 33 hispanic  2 . 30 other
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
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
8
Latent Toxoplasmosis
Negative
Note: N = 4038
Source: NHANES III
Positive
9
10
11
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
2
3
4
5
6
7
. line yhat01 yhat11 piratio1
0
5
piratio1
yhat01
10
yhat11
2
3
4
5
6
7
. line yhat01 yhat11 piratio1
0
5
piratio1
yhat01
10
yhat11
7
6
5
4
3
2
0
5
piratio1
yhat01
10
yhat11
2
3
4
5
6
7
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
0
5
piratio1
yhat01
10
yhat11
2
3
4
5
6
7
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as P
0
5
piratio1
yhat01
10
yhat11
2
3
4
5
6
7
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
0
5
piratio1
yhat01
10
yhat11
2
3
4
5
6
7
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
0
5
piratio1
yhat01
10
yhat11
2
3
4
5
6
7
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
0
5
piratio1
yhat01
10
yhat11
0
1
2
3
4
5
6
7
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
0
5
piratio1
yhat01
10
yhat11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
5
piratio1
yhat01
10
yhat11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
5
Poverty-to-income Ratio
yhat01
yhat11
10
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
yhat01
8
yhat11
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
yhat01
8
yhat11
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
yhat01
8
yhat11
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
8
Latent Toxoplasmosis
yhat01
yhat11
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
8
Latent Toxoplasmosis
yhat01
yhat11
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
8
Latent Toxoplasmosis
Negative
Positive
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
8
Latent Toxoplasmosis
Negative
Note: N = 4038
Source: NHANES III
Positive
9
10
11
Figure 4.
Model-based Predictions of the Symbol-Digit Learning Test:
Interaction Between Latent Toxoplasmosis and Poverty-to-income Ratio as Piecewise
7
6
5
4
3
2
1
0
0
1
2
3
4
5
6
7
Poverty-to-income Ratio
8
Latent Toxoplasmosis
Negative
Note: N = 4038
Source: NHANES III
Positive
9
10
11
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/
```