Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: FW: Max/Min and Growth rates among subsample(by year) of panel data
From
Nickolas Lyell <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: FW: Max/Min and Growth rates among subsample(by year) of panel data
Date
Fri, 16 Aug 2013 12:31:22 -0400
Hi,
I've been trying to analyze a large database of counties and their economic indicators from 1990-2013.
I have it formatted long by fips number (a unique identifier for each US county) and year, with the indicators wide.
I am trying to calculate several indicators within a subsample of years by county. For instance, I would like to know the peak pre-recession level of real GDP (RGDP). Since I don't want the 90's or post-recession data to show up, I would like to limit the maximum to 2002-2009.
To get this value and its year as variables in the dataset, I did the following:
sort fips_num year
by fips_num: egen peakRGDP = max(RGDP) if year >2001 & year <2010 bysort fips_num (peakRGDP): replace peakRGDP = peakRGDP[1] by fips_num: gen peakRGDPyear = year if peakRGDP==RGDP bysort fips_num (peakRGDPyear): replace peakRGDPyear = peakRGDPyear[1]
and the same thing for the trough value:
sort fips_num year
by fips_num: egen troughRGDP = min(RGDP) if year >peakRGDPyear bysort fips_num (troughRGDP): replace troughRGDP = troughRGDP[1] by fips_num: gen troughRGDPyear = year if troughRGDP==RGDP bysort fips_num (troughRGDPyear): replace troughRGDPyear = troughRGDPyear[1]
which works, but feels clunky. And neither does it help me to calculate annualized growth rates among subsamples of years. I would like to find out, for instance the annualized growth rate of RGDP from 1990-peakRGDPyear, peakRGDPyear-troughRGDPyear, troughRGDPyear-2013.
Is there a better way to do this? Maybe I need to convert my data back to wide with respect to year and use rowmax and rowmin functions, but that also seems clunky.
---
Nick Lyell
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/