Statalist The Stata Listserver


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

Re: st: Help Creating a Lagged Variable - REVISED


From   Michael Horowitz <horowitz@fas.harvard.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Help Creating a Lagged Variable - REVISED
Date   Tue, 12 Sep 2006 16:30:41 -0400 (EDT)

Thanks for the suggestions -- I got the variable set up perfectly.

One more question. So now I have my "change" variable. I would like to generate a new variable that counts the number of years since the last regime change. How would I do that?

Any help would be very much appreciated. . . .

Sincerely,
Michael Horowitz


On Tue, 12 Sep 2006, Tom Boonen wrote:


I am interested in creating a lagged variable for each country for each
year that will take on the value of the start year for the dataset if
no regime change has occurred for that country since the beginning of the
dataset and the year of the regime change if a regime change has occurred.
There is probably a more elegant way to do this. But one posibility is:

egen change_indicator1 = sum(regime_change), by (country)

now this change_indicator is 0 for those countries that did not
expereince a change over the  whole time period and >0 for those that
did.

so:
gen lagged_var = 1945 if change_indicator==0

now in lagged var we also want als the year of the regime change if a
regime change has occurred.

egen change_indicator2 = sum(regime_change), by (country year)

and then:
replace lagged var = year if change_indicator2==1

Hope this helps.

Tom Boonen


On 9/12/06, Michael Horowitz <horowitz@fas.harvard.edu> wrote:
To whom it may concern:

I have data set up in country-year format, where there is one observation
per country per year.  There is also a regime change variable that is a 0
if no regime change occurred in that year and a 1 otherwise.  The dataset
runs from 1945-2002.

I am interested in creating a lagged variable for each country for each
year that will take on the value of the start year for the dataset if
no regime change has occurred for that country since the beginning of the
dataset and the year of the regime change if a regime change has occurred.

For example, what I want is something where for the observations for the
United States in 1992, the value of the lagged variable is 1945, since
there has been no regime change in the United States, according to the
definition I am using, since 1945.  However, for China in 1992, the value
of the lagged variable is 1949, since that is the beginning of the
Communist era in China.

However, I am not sure how to create this variable. . any advice would be
*very much* appreciated. . .thank you for your help in advance.

Sincerely,
Michael Horowitz
*
*   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/

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

*******************************************************************************

Michael Horowitz
83 Beacon St., Apt. 3
Somerville, MA 02143
*
*   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