Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Re: compute a variable with the same formula for each year
From
"Joseph Coveney" <[email protected]>
To
<[email protected]>
Subject
st: Re: compute a variable with the same formula for each year
Date
Fri, 12 Oct 2012 05:21:16 +0900
Urbain Thierry YOGO wrote:
I have a variable year going from 2000 to 2010. I want to compute the
following formula for each year a=10exp(2t). But the point is that i
need the respective observations to constitute a variable, not
independent scalar. I have tried the following code:
egen t=group(year)
forvalue t=1(1)11{
gen y`t'=10*exp(2*`t')
}
gen a=year
replace a=y1 if year==2000
replace a=y2 if year==2001
replace a=y3 if year==2002
.
.replace a=y11 if year==2010
Please is there a simple code to do this? thank you
--------------------------------------------------------------------------------
Would it be something like this?
generate double a = 10 * exp(2 * (year - 1999))
Joseph Coveney
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/