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

Michael Horowitz


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

*   For searches and help try:

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