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

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

From   Michael Hanson <>
Subject   st: Extract sample start/end dates of time series regression?
Date   Sat, 07 Nov 2009 12:24:49 -0500

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, 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


*   For searches and help try:

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