Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Indexing Question

From   "Nick Cox" <>
To   <>
Subject   RE: st: Indexing Question
Date   Mon, 29 Aug 2005 17:26:44 +0100

Your dates are to me ambiguous. 
I'll guess your dates are month/day/year. 

gen OK = !inlist(date, d(2jul2005), d(7jul2005)) 
bysort id (OK date) : gen pc_change = 100 * (X[2] - X[1])/X[1] if OK[1] == 0 & OK[2] == 0 

The trickery with !inlist() is just a way to make the 
sort order convenient. The OK dates will be coded 0 
and sorted to the first two observations in each panel. 

The result will be repeated for each observation in the panel. 
Use -egen, tag()- or some other method to select just one. 

Note that your example shows repeated values for 
panel 3. 


kelly johnson
> What if I want to do the same calculation, but in a specific 
> time period. 
> Eg. in my data set, I want to calculate teh percentage change 
> in X between 
> 7/2/05-7/5/05 (for all observations with data in that time 
> period). Thank you!

*   For searches and help try:

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