Graeme Inglis
> x is a categorical variable and can take the values 1,2,3,4.
> x is taken at periods 0(baseline),1 ,2 ,3,.. and varies over time.
> Values of x at these periods is x0, x1, x2, x3,....
> I want to generate a newvar y = x0, value at baseline, such that
> y0=y1=y2=y3=...
>
> If I do 'gen y = x if period==0' I only get values for y in period '0'.
>
If -x- is observed just once when -period- is 0, then
su x if period == 0, meanonly
will report on a single observation, and what is
left behind in r(min), r(max), etc. will be the
same value, so following with
gen y = r(min)
will put the same constant in each value of the variable.
Alternatively, if
sort period
-sort-s the observation with -period- 0
to the first observation, then following with
gen y = x[1]
should suffice. Having said all that, there is
some inefficiency in holding the same number
repeatedly. It might be better to hold it in a macro
or scalar.
Nick
n.j.cox@durham.ac.uk
*
* 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/