|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Extract sample start/end dates of time series regression?
From |
Michael Hanson <[email protected]> |
To |
[email protected] |
Subject |
Re: st: Extract sample start/end dates of time series regression? |
Date |
Sat, 07 Nov 2009 14:39:16 -0500 |
Thanks, Austin: -summarize ..., meanonly-, with reference to r(min)
and r(max), does the trick. D'oh -- should have thought of that myself!
To close this thread: since I need local macros in Stata date format
for my application (which, unlike the toy example below, uses monthly
data), I have done something like the following:
foreach c in local cc {
... // Estimation here
summ date if e(sample), meanonly
local Tbeg_`c' : disp %tm r(min)
local Tend_`c' : disp %tm r(max)
... // More analysis here, using the start/end date macros
}
Additional thanks to Martin Weiss for earlier insight into the proper
syntax for the extended macro function -display- used above: <http://www.stata.com/statalist/archive/2009-06/msg00318.html
>.
Best,
Mike
On Nov 7, 2009, at 12:39 PM, Austin Nichols wrote:
Like this, maybe?
use http://www.stata-press.com/data/r11/pennxrate.dta, clear
egen i=group(country), label
su i, mean
g low=.
g high=.
qui forv i=1/`r(max)' {
reg lnrxrate L.lnrxrate if i==`i'
su year if e(sample), mean
replace low=r(min) if i==`i'
replace high=r(max) if i==`i'
}
bys i:g byte f=_n==1
li i low high if f==1, noo clean
--could also put in a matrix or locals, but may be easier to have in
variables for later reference via tin() etc.
On Sat, Nov 7, 2009 at 12:24 PM, Michael Hanson <[email protected]>
wrote:
I have a series of regressions that I am estimating country-by-
country,
using a -foreach- loop. (The data are organized wide; this is to
produce a
table of cross-country results, not for a panel estimation.) The
sample for
each country, however, has potentially different start and end
dates, and I
would like to somehow extract these dates from the estimates as I
loop
through them. Ideally, I'd like to place the dates either in a
matrix or
(better) a series of local macros so that I can (1) list the start/
end dates
of each country's estimates in a custom-made table of results, and
(2)
reference them with -tin()- function calls for post-processing of
the data
country-by-country.
Unfortunately, I have had no luck figuring out how to do this in
Stata. This
kind of information is readily available in packages designed from
the
ground up for time series analysis (RATS and EViews come to mind),
but I'd
like to stay in Stata if possible. Suggestions are welcome; below
is an
artificial example that gets at the issue. In it, I would like to
return
values that identify the sample start (`Tbeg') and end (`Tend')
dates as
follows:
country Tbeg Tend
AFG 1971 2003
ANT 1972 2003
ARE 1971 2001
// Begin sample code
use http://www.stata-press.com/data/r11/pennxrate.dta, clear
keep in 1/102
keep country year lnrxrate
reshape wide lnrxrate, i(year) j(country) string
replace lnrxrateANT = . in 1
replace lnrxrateARE = . in -2/l
tsset year
local cc AFG ANT ARE
foreach c of local cc {
reg lnrxrate`c' L.lnrxrate`c'
gen smpl`c' = e(sample)
}
list year smpl* in 1/3
list year smpl* in -3/l
// End sample code
Thanks,
Mike
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/