Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Preventing -estout- from overwriting e(labels) in successive runs
From
Bert Jung <[email protected]>
To
[email protected]
Subject
st: Preventing -estout- from overwriting e(labels) in successive runs
Date
Wed, 16 Apr 2014 14:07:18 -0400
Dear Statalisters,
I am hoping to get -estout- (written by Ben Jann, link below) to
assign labels to factor variables. This has been discussed previously
(links below) but apparently not yet been resolved.
My approach is to place the labels into a local and attach these to
the estimation set as e(labels) using -estadd-. In the process of
trying this I noticed that sometimes -estout- appears to overwrite
labels stored in e(labels), which can lead to labels being dropped. I
am hoping that someone might know how to prevent this.
I paste below example code with commentary as well as the associated output.
Thanks for your thoughts,
Bert
** Discussion on labels for factor variables in -estout-, with
solutions summarized by Bert Lloyd
http://www.stata.com/statalist/archive/2012-10/msg00139.html
** Ben Jann's fabulous -estout-
http://repec.org/bocode/e/estout/index.html
*********** Example code **************
which estout
sysuse auto, clear
eststo clear
eststo set1: estpost tabstat price in 1/15, by(make)
* To get the labels, use: varlabels(`e(labels)'). This works nicely.
estout set1, cells(mean)
estout set1, cells(mean) varlabels(`e(labels)')
* Note that e(labels) as assigned to this estimation set contains the
relevant labels.
ereturn list
di `"`e(labels)'"'
* The problem appears when preparing another estimation set.
* This affects the labeling by -estout- IF the levels of the
additional set < original set.
* Example:
* set2 has as many levels/labels => no problem
eststo set2: estpost tabstat price in 21/35, by(make)
estout set1, cells(mean) varlabels(`e(labels)')
* set3 has as FEWER levels/labels => -estout- omits some labels
eststo set3: estpost tabstat price in 21/23, by(make)
estout set1, cells(mean) varlabels(`e(labels)')
* It seems that -estout- overwrites the e(labels) that were attached
to est1. It now only contains 3 entries.
di `"`e(labels)'"'
********* End of example code ********
*********** Output *************
. which estout
c:\ado\plus\e\estout.ado
*! version 3.13 06aug2009 Ben Jann
.
. sysuse auto, clear
(1978 Automobile Data)
. eststo clear
.
. eststo set1: estpost tabstat price in 1/15, by(make)
Summary statistics: mean
for variables: price
by categories of: make
make | e(mean)
-------------+-----------
1 | 4099
2 | 4749
3 | 3799
4 | 4816
5 | 7827
6 | 5788
7 | 4453
8 | 5189
9 | 10372
10 | 4082
11 | 11385
12 | 14500
13 | 15906
14 | 3299
15 | 5705
-------------+-----------
Total | 7064.6
category labels saved in macro e(labels)
.
. * To get the labels, use: varlabels(`e(labels)'). This works nicely.
. estout set1, cells(mean)
-------------------------
set1
mean
-------------------------
1 4099
2 4749
3 3799
4 4816
5 7827
6 5788
7 4453
8 5189
9 10372
10 4082
11 11385
12 14500
13 15906
14 3299
15 5705
Total 7064.6
-------------------------
. estout set1, cells(mean) varlabels(`e(labels)')
-------------------------
set1
mean
-------------------------
AMC Concord 4099
AMC Pacer 4749
AMC Spirit 3799
Buick Cent~y 4816
Buick Elec~a 7827
Buick LeSa~e 5788
Buick Opel 4453
Buick Regal 5189
Buick Rivi~a 10372
Buick Skyl~k 4082
Cad. Deville 11385
Cad. Eldor~o 14500
Cad. Seville 15906
Chev. Chev~e 3299
Chev. Impala 5705
Total 7064.6
-------------------------
.
. * Note that e(labels) as assigned to this estimation set contains
the relevant labels.
. ereturn list
scalars:
e(N) = 15
macros:
e(_estimates_name) : "set1"
e(cmd) : "estpost"
e(subcmd) : "tabstat"
e(stats) : "mean"
e(vars) : "price"
e(byvar) : "make"
e(labels) : "1 `"AMC Concord"' 2 `"AMC Pacer"' 3 `"AMC
Spirit"' 4 `"Buick Century"' 5 `"Buick Electra"' 6 `"Buick LeSabre"' 7
`"Buick Opel"' 8 `"Buick.."
matrices:
e(mean) : 1 x 16
. di `"`e(labels)'"'
1 `"AMC Concord"' 2 `"AMC Pacer"' 3 `"AMC Spirit"' 4 `"Buick Century"'
5 `"Buick Electra"' 6 `"Buick LeSabre"' 7 `"Buick Opel"' 8 `"Buick
Regal"' 9 `"Buick Riviera"' 1
> 0 `"Buick Skylark"' 11 `"Cad. Deville"' 12 `"Cad. Eldorado"' 13 `"Cad. Seville"' 14 `"Chev. Chevette"' 15 `"Chev. Impala"'
.
.
. * The problem appears when preparing another estimation set.
. * This affects the labeling by -estout- IF the levels of the
additional set < original set.
.
. * Example:
.
. * set2 has as many levels/labels => no problem
. eststo set2: estpost tabstat price in 21/35, by(make)
Summary statistics: mean
for variables: price
by categories of: make
make | e(mean)
-------------+-----------
1 | 4010
2 | 5886
3 | 6342
4 | 4389
5 | 4187
6 | 11497
7 | 13594
8 | 13466
9 | 3829
10 | 5379
11 | 6165
12 | 4516
13 | 6303
14 | 3291
15 | 8814
-------------+-----------
Total | 6777.867
category labels saved in macro e(labels)
. estout set1, cells(mean) varlabels(`e(labels)')
-------------------------
set1
mean
-------------------------
Dodge Dipl~t 4099
Dodge Magnum 4749
Dodge.. Re~s 3799
Ford Fiesta 4816
Ford Mustang 7827
Linc. Cont~l 5788
Linc. Mark V 4453
Linc. Vers~s 5189
Merc. Bobcat 10372
Merc. Cougar 4082
Merc. Marq~s 11385
Merc. Mona~h 14500
Merc. XR-7 15906
Merc. Zephyr 3299
Olds 98 5705
Total 7064.6
-------------------------
.
. * set3 has as FEWER levels/labels => -estout- omits some labels
. eststo set3: estpost tabstat price in 21/23, by(make)
Summary statistics: mean
for variables: price
by categories of: make
make | e(mean)
-------------+-----------
1 | 4010
2 | 5886
3 | 6342
-------------+-----------
Total | 5412.667
category labels saved in macro e(labels)
. estout set1, cells(mean) varlabels(`e(labels)')
-------------------------
set1
mean
-------------------------
Dodge Dipl~t 4099
Dodge Magnum 4749
Dodge.. Re~s 3799
4 4816
5 7827
6 5788
7 4453
8 5189
9 10372
10 4082
11 11385
12 14500
13 15906
14 3299
15 5705
Total 7064.6
-------------------------
.
.
. * It seems that -estout- overwrites the e(labels) that were attached
to est1. It now only contains 3 entries.
. di `"`e(labels)'"'
1 `"Dodge Diplomat"' 2 `"Dodge Magnum"' 3 `"Dodge St. Regis"'
******************************
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/