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

From |
David Kantor <dkantor@jhu.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Newbie question on creating variable |

Date |
Mon, 01 Mar 2004 15:45:54 -0500 |

Try this:

egen byte n1 = sum(year==1970) , by(countrycode)

assert n1==1 // make sure only one per country

drop n1

gen int temp1 = gdp if year==1970

egen int gdp1970 = max(temp1) by(countrycode)

drop temp1

gen int diff = gdp1970 -gdp

I assumed that int is a good type for gdp.

Also, the first part assures that there is exactly one case with year==1970 per country. You could be a bit more general and assure that there is at most one case (assert n1<=1).

Maybe there is some other obvious solution I've overlooked.

I hope this helps.

-- David

At 02:14 PM 3/1/2004 -0500, AmBush (Kakatua Kutta) wrote:

countrycode year gdp

BAN 1960 65

BAN 1965 75

BAN 1970 85

CAN 1960 25

CAN 1965 35

CAN 1970 45

Dear Stata users,

Lets say I have the above data set. I want to create a variable which measures the difference between the gdp in year 1970 and gdp in 1965 for each country. That is if "diff" is the new variable it would be diff = gdp(1970)-gdp (1965) for each country.

I am a new user and already spent hours on this. I would much appreciate your help.

Thanks in advance

AmBush

[...]

David Kantor Institute for Policy Studies Johns Hopkins University dkantor@jhu.edu 410-516-5404 * * 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/

**References**:**st: Newbie question on creating variable***From:*"Kakatua Kutta" <ambush@earthling.net>

- Prev by Date:
**Re: st: Newbie question on creating variable** - Next by Date:
**Re: st: RE: Kapm command- New version?** - Previous by thread:
**Re: st: Newbie question on creating variable** - Next by thread:
**Re: st: Newbie question on creating variable** - Index(es):

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