Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Extract sample start/end dates of time series regression?


From   Austin Nichols <[email protected]>
To   [email protected]
Subject   Re: st: Extract sample start/end dates of time series regression?
Date   Sat, 7 Nov 2009 12:39:59 -0500

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/



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