stata intro2 by 4aV8u80

VIEWS: 6 PAGES: 7

									Econometric Analysis Using Stata

          Introduction
          Time Series
           Panel Data
      Time Series Analysis Using Stata

• Declare time series data and variables
  – tsset
• Time series operators
  – L.; F.; D.; S.
• Commands with time series options
  – regress …, if tin(.,.)
  – generate
  – summarize
     Example: U.S. GDP Growth
                  gdp2005.txt
                  gdp2005.dta

•   Time series setup
•   Time series operators
•   Time series line plot (graphics)
•   Time series regression
                          gdp1.do
* Read text data file (.asc) and covert it to Stats dataset file (.dta)
infile year quarter gdp pgdp using “\course12\ec572\data\gdp2005.txt"
describe
summarize
label data "U. S. GDP: 1947.1-2011.4"
label variable gdp "GDP (billion of current dollars)"
label variable pgdp "Implicit GDP price deflator (year 2005 = 100)"
* delete the 1st line of variable names
drop in 1
* create a time series dataset
generate time=yq(year,quarter)
tsset time, quarterly
label variable time "Time"
drop year quarter
describe
summarize
* save it as a Stata dataset, if it has not done yet
save "\course12\ec572\data\gdp2005"
                     gdp2.do
* use graph to represent the data
* a graph is worth of thousand words
clear
use http://web.pdx.edu/~crkl/ec572/data/gdp2005.dta
* is this time series data?
tsset
d
su
* generate new variable
gen rgdp=100*gdp/pgdp
gen lrgdp=ln(rgdp)
gen gq=100*D.lrgdp
gen ga=100*(lrgdp-L4.lrgdp)
su
* time series line plots
tsline rgdp, name(rgdp)
tsline gq ga, name(growth)

* time regression
reg lrgdp time
           Example: SP-500
                sp500new.xml

•   Reading from an Excel XML database file
•   Time series (daily) data setup
•   Time series line plot (graphics)
•   Time series analysis
                         sp500new1.do
/*
** Time Series Analysis of U.S. SP500 Stock Market Index
** Latest update: 3/1/2010
*/
* xmluse "\Course12\EC572\data\sp500new.xml", doctype(excel) sheet(2007) cells(A2:G276) clear
* xmluse "\Course12\EC572\data\sp500new.xml", doctype(excel) sheet(2008) cells(A2:G254) clear
* xmluse "\Course12\EC572\data\sp500new.xml", doctype(excel) sheet(2009) cells(A2:G253) clear
* xmluse "\Course12\EC572\data\sp500new.xml", doctype(excel) sheet(2010) cells(A2:G253) clear
xmluse "\Course12\EC572\data\sp500new.xml", doctype(excel) sheet(2011) cells(A2:G258) clear

gen date=var1
gen vol=var6
gen idx=var7
tsset date, daily
drop var*

gen r=100*(ln(idx)-ln(L.idx))
tsline idx, name(SP500_INDEX,replace)
tsline r, name(SP500_Returns,replace)

*   Is IDX stationary? IDX~I(1)
*   Is R stationary? R~I(0)
*   ARMA and ARCH structures of R
*   SP500 Forecasts?

								
To top