Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Getting entity specific slopes in one command


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: Getting entity specific slopes in one command
Date   Mon, 31 Aug 2009 06:57:45 +0000 (GMT)

Both are just different ways of presenting exactly the same model, i.e. the lead to exactly the same predictions. Since you want to do an imputation model, this is all you care about. So choose whichever method you find easiest. Since you do imputation you should be using -ice- in which case you will have to make those dummies and interactions yourself. Some shortcuts that can help making all these variables are shown in the example below. 

Hope this helps,
Maarten

*--------------- begin example -------------
clear
input country year pop
      1       1960 .
      1       1961 1
      1       1962 3
      1       1963 5
      1       1964 7
      2       1960 4
      2       1961 8
      2       1962 12
      2       1963 .
      2       1964 .
      3       1960 10
      3       1961 9
      3       1962 .
      3       1963 8
      3       1964 7
end

// get the number of countrys
levelsof country
local c : word count `r(levels)'

// create country dummies
tab country, gen(dcountry)

// create interaction terms
forvalues i = 1/`c' {
	gen dcountry`i'Xyear = dcountry`i'*year
}

// each country has it's own constant 
// and effect of year
reg pop dc* , nocons
predict pophat1

// dummy coding
drop dcountry1*
reg pop dc* year
predict pophat2

// predictions are exactly the same
twoway scatter pophat*, aspect(1)
*------------------- end example -----------------
( For more on how to use examples I sent to statalist see:
http://www.maartenbuis.nl/stata/exampleFAQ.html )


-----------------------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany

http://www.maartenbuis.nl
-----------------------------------------


--- On Mon, 31/8/09, Amanda Agan <[email protected]> wrote:

> From: Amanda Agan <[email protected]>
> Subject: st: Getting entity specific slopes in one command
> To: [email protected]
> Date: Monday, 31 August, 2009, 12:44 AM
> Hello,
> 
> This is somewhat a follow-up to "Error with MIM installed
> command" but
> can be read separately and completely on it's own and does
> not
> currently have anything to do with the mim command.
> 
> I could not find a sysuse dataset that would allow me to
> demonstrate
> my issue so please indulge me and imagine you had a dataset
> with:
> county identifiers
> year
> population
> 
> Some population values are missing. You posit that
> population will be
> a function of time and time squared and want to fill in
> missing values
> of population that way (this is just a simplified example,
> please no
> comments on this method of doing this, only on the best way
> to do so,
> thank you!).  You also want county-specific slopes and
> intercepts
> (different coefficients and constant for each county).
> 
> One way to do this would be
> gen yearsq=year*year
> 
> reg population year yearsq if county==1
> predict pop1 if county==1
> reg population year yearsq if county==2
> predict pop2 if count==2
> 
> etc....
> 
> But I want to do this in one command. Unfortunately xi: reg
> i.county
> i.county|year i.county|yearsq, doesn't give exactly the
> right result
> because the 'main' effects of year and yearsq are left in
> the
> regression (the uninteracted effects) which we don't want
> (although
> this notation does eliminate the 'main effects' of county,
> which are
> in there anyways).
> 
> The user installed command desmat (ssc install desmat) gets
> around this problem:
> desmat: reg population county county.@year county.@yearsq,
> nocons
> predict population_desmat
> 
> this will give the same predicted results as the reg and
> predict for
> each state individually.
> 
> Is this the best way to do this?
> (I may follow up with the best way to do the above command
> along with
> multiple imputation, which was the thrust of my original
> question, if
> it is true the desmat is the only way to do this in one
> command....)
> 
> Thank you for your consideration and time!
> Amanda Agan
> 
> *
> *   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/
> 


      

*
*   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/



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