Professional Documents
Culture Documents
Julian Reif
University of Chicago
Stata Conference Boston
July 15, 2010
regsave, svret
Analyzing
Excel PivotTables
Presenting
Run analyses
Store and manipulate results
Output results into a table linked to a paper, MS Excel, etc.
Storing output
Storing output
Stata commands usually store output in e() and r()
=
=
=
=
=
=
=
=
74
74
6 165.256756756757
8 699525.974268789
2 949.495884768919
3 291
1 5906
4 56229
Can save macros and scalars stored in e(), r(), and s()
Syntax:
svret [classlist] [, long type(type)
format(%fmt) keep(returnlist)]
where
classlist is one or more of the following: e, r, s, all,
type can be one of the following: all, scalars, or macros,
and
returnlist is a list of returned results currently in
memory, e.g., r(N).
6
svret: example 1
. s ys us e au to , c le ar
( 19 78 A ut om ob ile D at a)
. s um m pr ic e
V ar ia bl e
O bs
Mea n
pr ic e
74
61 65 .25 7
. s vr et , lo ng fo rm at (% 8. 2f c)
. l is t
va ri ab le
c on te nt s
1.
2.
3.
4.
5.
r( N)
r( Va r)
r( ma x)
r (m ea n)
r( mi n)
74
8, 69 9, 52 6
1 5, 90 6
6 ,1 65 .2 6
3, 29 1
6.
7.
8.
r (s d)
r( su m)
r( su m_ w)
2 ,9 49 .5 0
45 6, 22 9
74
S td . De v.
2 94 9. 49 6
Mi n
M ax
3 29 1
1 59 06
(Abbreviated) syntax:
regsave [coeflist] [using filename] [,
tstat pval ci level(#) addlabel(string)
addvar(string) table(name, *) *]
regsave: example 1
. sysuse auto, clear
(1978 Automobile Data)
.
. regress price mpg trunk
Source
SS
df
MS
Model
Residual
141126459
493938937
2
71
70563229.4
6956886.44
Total
635065396
73
8699525.97
price
Coef.
mpg
trunk
_cons
-220.1649
43.55851
10254.95
Std. Err.
65.59262
88.71884
2349.084
t
-3.36
0.49
4.37
Number of obs
F( 2,
71)
Prob > F
R-squared
Adj R-squared
Root MSE
P>|t|
0.001
0.625
0.000
=
=
=
=
=
=
74
10.14
0.0001
0.2222
0.2003
2637.6
-89.3769
220.4589
14938.89
.
. regsave, tstat pval ci
.
. list
1.
2.
3.
var
coef
stderr
tstat
pval
ci_lower
ci_upper
r2
mpg
trunk
_cons
-220.1649
43.55851
10254.95
65.59263
88.71884
2349.084
-3.356549
.4909725
4.36551
.0012707
.6249601
.0000423
-350.9529
-133.3418
5571.01
-89.3769
220.4588
14938.89
74
74
74
.2222235
.2222235
.2222235
Analyzing output
10
11
regsave: example 2
sysuse auto, clear
tempfile tmpfile
gen lnprice = ln(price)
local replace "replace"
foreach reg in "probit" "logit" "regress" {
foreach regressors in "lnprice" "lnprice rep78" "lnprice rep78 trunk" {
foreach stderr in "vce(robust)" "vce(cluster foreign)" "" {
`reg foreign `regressors, `stderr
regsave using "`tmpfile", p \\\
addlabel(vce,`stderr,regressors,`regressors,reg,`reg) `replace
local replace "append"
}
}
}
* Format and outsheet results for use in PivotTable
use "`tmpfile", clear
replace var = subinstr(var,"foreign:","",.)
outsheet using results.txt, replace
12
PivotTable: view 1
13
PivotTable: view 2
14
Presenting output
15
re g
a reg
1.
2.
3.
4.
5.
mp g_c oef
m pg_ std err
t run k_c oef
tru nk_ std err
h ead roo m_c oef
-17 3.9 5
(87 .75 )
8 0.9 1
( 119 .82 )
-68 0.2 9
- 139 .90
( 82. 30)
38 .45
(1 12. 24)
- 596 .43
6.
7.
8.
9.
10.
( 486 .01 )
2 3.2 9
(27 .03 )
6 ,41 6.9 5
(6, 036 .94 )
(4 53. 11)
65 .43
( 28. 04)
-1 895 .75
( 6,1 26. 44)
11.
12.
N
r2
74
0.2 5
74
0 .36
16
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
17
var
reg
areg
mpg
-173.95
(87.75)
80.91
(119.82)
-680.29
-139.90
(82.30)
38.45
(112.24)
-596.43
(486.01)
23.29
(27.03)
6,416.95
(6,036.94)
(453.11)
65.43
(28.04)
-1895.75
(6,126.44)
74
0.25
74
0.36
trunk
headroom
length
_cons
N
r2
(Abbreviated) syntax:
texsave [varlist] using filename [if]
[in] [, title(string) size(numlist)
marker(string) hlines(numlist)
footnote(*) booktabs frag replace *]
18
texsave: example 1
. sysuse auto.dta, clear
(1978 Automobile Data)
. texsave make mpg trunk if price > 8000 using "table.tex", title(MPG and trunk space) footnote("*Variable trunk is measu
> red in cubic feet") replace
19
texsave: example 2
sysuse auto, clear
tempfile tmpfile
gen lnprice = ln(price)
local replace "replace"
foreach reg in "probit" "logit" "scobit" {
`reg foreign lnprice rep78 trunk
regsave using "`tmpfile", addlabel(Regression,"`reg") \\\
table(`reg, asterisk(5 1) parentheses(stderr) format(%8.3fc)) `replace
local replace "append"
}
* Create and format LaTeX table
use "`tmpfile", clear
replace var = subinstr(var,"foreign:","",1)
replace var = subinstr(var,"_coef","",1)
replace var = "" if strpos(var,"stderr")!=0
replace var = "lnalpha" if strpos(var,"lnalpha")!=0
label variable var "Variable name"
local fn "A */** next to coefficient indicates significance at the 5/1\% level."
texsave using "table.tex", title(My regressions) booktabs hlines(10) \\\
autonumber footnote("`fn") varlabels replace
20
21
frag
Give the table a tag and specify its alignment and location
22
Email: jreif@uchicago.edu
23