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

RE: st: Indexing Question


From   "kelly johnson" <[email protected]>
To   [email protected]
Subject   RE: st: Indexing Question
Date   Tue, 30 Aug 2005 10:53:30 -0400

What if some observations are only in part of that range? suppose i want to calculate the % change in X for all observations from 7/2/05-7/5/05. Since I have a large database, there may be observations that are in part of the period (e.g. 7/3/05-7/4/05). I want to calculate the % change in X for all observations that appear throughout that period, or a portion of that period. Also, how can I make it output a single number (for this variable) for each id?

Thank you for your assistance.

kelly


From: "Nick Cox" <[email protected]>
Reply-To: [email protected]
To: <[email protected]>
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.

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/
_________________________________________________________________
Don�t just search. Find. Check out the new MSN Search! http://search.msn.click-url.com/go/onm00200636ave/direct/01/

*
* 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/




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