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]
Re: st: missing factor variables in table of estimates
From
[email protected] (Jeff Pitblado, StataCorp LP)
To
[email protected]
Subject
Re: st: missing factor variables in table of estimates
Date
Wed, 22 Feb 2012 11:40:40 -0600
Lloyd Dumont <[email protected]> is having trouble with -estimates table-:
> I am having trouble recovering estimates from two-way multiplicative
> interactions created using Stata 11's facility for factor variables.
> Â
> Here is an exampleâ?¦
>
> code:
> . Â xtreg Y X1, fe
> . Â estimates store M1
> . Â xtreg Y c.X2##c.X1 c.X3##c.X1, fe
> . Â estimates store M2
> . Â estimates table M1 M2, stats(N N_g r2_o)
> star(.05 .01 .001) keep(c.X2##c.X1 c.X3##c.X1) b(%9.2f) stfmt(%9.2fc)
> style(oneline)
> Â
> generates:
> --------------------------------------------
> Â Â Â Variable |Â Â Â Â Â M1Â Â Â Â Â Â Â Â Â Â Â Â M2Â Â Â Â Â Â
> -------------+------------------------------
> Â Â Â Â Â Â Â Â Â X2 |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â -4.12**Â Â
> Â Â Â Â Â Â Â Â Â X1 |Â Â Â Â -1.12***Â Â (omitted)Â Â Â Â
> Â Â Â Â Â Â Â Â Â Â Â Â |
> Â Â c.X2#c.X1 |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 10.46**Â Â
> Â Â Â Â Â Â Â Â Â Â Â Â |
> Â Â Â Â Â Â Â Â Â X3 |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 5.65**Â Â
> Â Â Â Â Â Â Â Â Â X1 |Â Â Â Â -1.12***Â Â (omitted)Â Â Â Â
> Â Â Â Â Â Â Â Â Â Â Â Â |
> Â Â c.X3#c.X1 |Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â -14.66***Â
> -------------+------------------------------
> Â Â Â Â Â Â Â Â Â Â N |Â Â Â Â Â 3137Â Â Â Â Â Â Â Â Â Â 3137Â Â Â Â
> Â Â Â Â Â Â Â Â N_g |Â Â Â Â 31.00Â Â Â Â Â Â Â Â Â 31.00Â Â Â Â
> Â Â Â Â Â Â Â r2_o |Â Â Â Â Â 0.00Â Â Â Â Â Â Â Â Â Â 0.00Â Â Â Â
> --------------------------------------------
> Â Â Â Â Â Â legend: * p<.05; ** p<.01; ***
> p<.001
> Â
> There are a few problems here. First, looking down column M1, what can I do
> to prevent the estimate for X1 from displaying twice? Second, in M2, no
> estimate displays for the main effect of X1. In fact, it is omitted twice.
>
> So, how can one display estimates for ALL of the following variables, and
> have them display just once?
>
> X1
> X2
> X2
> * X1
> X3
> X3
> * X1
It looks like there are duplicate predictors in Lloyd's second model.
. Â xtreg Y c.X2##c.X1 c.X3##c.X1, fe
In this specification, X1 will show up twice in the varlist since this notation will expand to
. Â xtreg Y X2 X1 c.X2#c.X1 X3 X1 c.X3#c.X1, fe
Lloyd can use parens to simplify the specification, and remove the duplicates.
One option is
. Â xtreg Y c.(X2 X3)##c.X1, fe
which expands to
. Â xtreg Y X2 X3 X1 c.X2#c.X1 c.X3#c.X1, fe
The only other difficulty is that -estimates table- will need Lloyd to be
explicit in which coefficients to keep for the table because the '##' notation
isn't always going to work. We hope to fix this in a future update to
Stata 12.
Here is a working example (Stata 11 and Stata 12) using the 'nlswork' dataset,
I renamed some variables to line up with Lloyd's example so that Lloyd can cut
and past the Stata code into a do-file.
***** BEGIN:
webuse nlswork
xtset idcode
rename ln_w Y
rename tenure X1
rename age X2
rename ttl_exp X3
* Lloyd's revised example
xtreg Y X1, fe
estimates store M1
xtreg Y c.X1##c.(X2 X3), fe
estimates store M2
estimates table M1 M2, ///
stats(N N_g r2_o) ///
star(.05 .01 .001) ///
keep(c.X1 c.X2 c.X3 c.X1#c.X2 c.X1#c.X3) ///
b(%9.2f) ///
stfmt(%9.2fc) ///
style(oneline)
***** END:
The output from -estimates table- is
***** BEGIN:
--------------------------------------------
Variable | M1 M2
-------------+------------------------------
X1 | 0.03*** 0.07***
X2 | -0.01***
X3 | 0.04***
|
c.X1#c.X2 | -0.00***
|
c.X1#c.X3 | -0.00***
-------------+------------------------------
N | 28101 28101
N_g | 4,699.00 4,699.00
r2_o | 0.14 0.20
--------------------------------------------
legend: * p<.05; ** p<.01; *** p<.001
***** END:
--Jeff
[email protected]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/