Statalist


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

Re: st: How to 'predict' constant by region?


From   "Eva Poen" <eva.poen@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to 'predict' constant by region?
Date   Thu, 7 Aug 2008 08:16:44 +0100

Galina,

you need to use a loop in this case.

gen constant = .
levelsof region, local(reg)

foreach r of local reg {
   regress migration q1 q2 q3 if region==`r'
   replace constant = _b[_cons] if region==`r'
}

This code assumes that region is a numeric variable. I will work for
strings, but you'd have add quotes where necessary.

Hope this helps,
Eva


2008/8/7 Galina An <ang@kenyon.edu>:
> Dear statalist users,
> I was wondering if anybody encountered the following problem:
> when I run the following code, I need to save constants for different
> regions:
>
> by region: reg migration q1 q2 q3
> by region: gen constant=_b[_cons]
>
> However, I get the same constant for all regions.
> Can anybody give me a hint?
>
> --
> Galina An
> Assistant Professor
> Economics Department
> Kenyon College
>
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index