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

Re: st: Creating a Count Variable in STATA


From   "Andrew Felton" <[email protected]>
To   [email protected]
Subject   Re: st: Creating a Count Variable in STATA
Date   Sun, 03 Apr 2005 00:05:44 -0000

Or how about this:

sort ccode years
by ccode: gen nukecount = sum(nukes)

--- In [email protected], Paul Millar <paul.millar@s...> wrote:
> try this...
> 
> gen nyears=0
> label variable nyears "Number of years country has nukes"
> 
> sort ccode
> gen nukeyear=year*nukes
> by ccode: egen minyear=min(nukeyear) if nukeyear>0
> by ccode: replace nyears=year-minyear+1 if nukeyear>0
> drop nukeyear minyear
> 
> - Paul Millar
> Sociology
> University of Calgary
> 
> At 03:14 PM 02/04/2005, you wrote:
> >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/
> 
> *
> *   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/



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