Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Creating a Count Variable in STATA


From   Michael Horowitz <horowitz@fas.harvard.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: Creating a Count Variable in STATA
Date   Sat, 2 Apr 2005 17:14:33 -0500 (EST)

To whom it may concern:

I have a time series dataset organized by country year, with one entry per
year per country.  I want to create a count variable that measures the
number of years it has been since a given country has acquired nuclear
weapons, the variable of interest for my study.  But I am having trouble
getting the coding entirely right.  The variables that I "think" matter
here are:

-ccode: the country code for each country
-nukes: a binary variable that is 0 if a country does not have nuclear
weapons and a 1 if it has nuclear weapons
-year: this is pretty obvious. .

The current coding I have is:

gen nukecount=0
replace nukecount=(nukecount[_n-1]+1) if ((ccode==ccode[_n-1]) &
(nukes==1) & (nukes[_n-1]==1))

If anyone has some advice about what I am doing wrong and how to
potentialy correct it. . that would be fantastic and I would really
appreciate it.

Sincerely,
Michael Horowitz

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

Michael Horowitz
78 Kirkland Street, #1
Cambridge, MA 02138

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