Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: re: missing dummy variable


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: re: missing dummy variable
Date   Thu, 11 Oct 2007 10:31:59 +0100 (BST)

--- "Wallace, John" <John_Wallace@affymetrix.com> wrote:
> I have been exploring -xi3- recently, and I've been wondering why the
> e. option for generating indicator variables relative to the grand 
> mean doesn't work the way Kit and Maarten describe.  I've been
> playing with some toy datasets trying to figure out how to generate
> the 95% confidence intervals for the coefficient of the dropped
level.
> I've managed to deduce how to calculate the coefficient itself, but
> the standard errors and so forth aren't obvious.  

The parameter estimate of the dropped value is:
 -1 * sum(not dropped estimates)

As Kit noticed you can get it using -lincom-, but if you have many
variables some tricks might be very useful.

With -xi3- all not dropped variables will start with _I, so you can get
a list of all not dropped variables using:
unab varlist : _I*

This list of variable names is now stored in the local varlist. If you
could in this list replace all occurences of " _" with " + _" you would
get the expression of the sum of all not dropped variables. You can do
that like this:
local test : subinstr local varlist " _" " + _", all

Now you can easily use -lincom- even if you have many _I variables:
lincom -1*(`test')

I think that the display of this many parameters would call for a
graph, so in the example below I show how I would add such information
together into one graph. A lot of the tricks I use are explained here:
http://home.fsw.vu.nl/m.buis/wp/pvalue.html

*------------------ begin example ---------------
sysuse auto, clear
gen domestic = !foreign
rename make desc
gen make = word( desc,1)
tab make

xi3: regress mpg e.make
unab varlist : _I*
local test : subinstr local varlist " _" " + _", all
lincom -1*(`test')

sort make
by make : keep if _n == 1
keep make foreign

mata
b = st_matrix("e(b)")'

// remove constant
k = rows(b) - 1
b = b[1::k,1]

// add dropped level
b = st_numscalar("r(estimate)") \b

V = st_matrix("e(V)")
se = diagonal(cholesky(diag(V)))

// remove constant
se = se[1::k,1]

// add droped level
se = st_numscalar("r(se)") \ se

df = st_numscalar("e(df_r)")

ci = b :- invttail(df,0.025):*se, b :+ invttail(df,0.025):*se

idx = st_addvar("float",("b","lb","ub"))
st_store(.,idx,(b,ci))
end

sort b

egen xaxis = axis(b), label(make)

twoway rcap ub lb xaxis  || /*
    */ scatter b xaxis if foreign == 1, /*
    */ mcolor(red) msymbol(O) || /*
    */ scatter b xaxis if foreign == 0, /*
    */ mcolor(blue) msymbol(O)  /*
    */ xlab(1/23,valuelabel angle(45)) /*
    */ yline(0) /*
    */ ytitle("deviation in mpg from grand mean") /*
    */ xtitle("") /*
    */ legend(lab(1 "95%" "conf. int.") /*
           */ lab(2 "foreign")        /*
           */ lab(3 "domestic") )
*------------------ end example ---------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________ 
Want ideas for reducing your carbon footprint? Visit Yahoo! For Good  http://uk.promotions.yahoo.com/forgood/environment.html
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index