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.
Nick
[email protected]
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:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/