Dear Kelly:
A very similar question was asked by Fuaad last
week from the same email address.
With no missing values, this sounds like
bysort (date) : gen pc_change = 100 * (X[_N] - X[1]) / X[1]
Nick
[email protected]
kelly johnson
> I have a question regading calculations and indexing. Below I
> have an except
> of a larrge data set. How can I calculate the percentage
> change in the
> variable X from the earliest date to the last date (e.g. in
> the case where
> id==1, the percentage change in X from 7/1/05-7/6/05). I want
> to do this by
> id for all my observations (i have thousands of obsevations
> and the date
> periods are of varying lengths...). I know it's of the 'by
> id:' type of
> statements, but I just can't get it right. Thank you.
>
> date id X
> 7/1/05 1 .2
> 7/2/05 1 .3
> 7/3/05 1 .2
> 7/4/05 1 .1
> 7/5/05 1 .5
> 7/6/05 1 .6
> 6/16/05 2 .4
> 6/17/05 2 .4
> 6/18/05 2 .4
> 6/19/05 2 .2
> 6/20/05 2 .1
> 6/21/05 2 .3
> 6/22/05 2 .5
> 4/11/05 3 .2
> 4/12/05 3 .8
> 4/13/05 3 .7
> 4/14/05 3 .8
> 4/15/05 3 .2
> 4/16/05 3 .2
> 4/17/05 3 .3
> 4/18/05 3 .1
> 4/16/05 3 .5
> ...
*
* 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/