Brief Introduction to Stata 10 Time Analysis

download Brief Introduction to Stata 10 Time Analysis

of 11

Transcript of Brief Introduction to Stata 10 Time Analysis

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    1/11

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    2/11

    2

    IntheTimeunitanddisplayformatforthetimevariable sectionselecttheformatofthedata,whichinourcasewouldbeYearly.ThenclickeitherSubmitorOKbuttontocompletethecommand.

    Thiswholeprocesscanalsobeperformedusingthecommandinterface.Writetssetyear,yearlyinthe

    commandwindowforthepresentcase.Ifforexample,indatathetimevariableisdefinedastimeand

    the format is monthly, then all one need to write in the command window is tsset time, monthly

    Similarlyhaditbeaquarterlydatarequiredtowritetssettime,quarterly.Thefollowingoutputwillbe

    displayed:

    .tssetyear,yearly

    timevariable:year,1981to2004

    delta:1year

    Timeseriesplotofvariables

    Thefirstthingoneshoulddointimeseriesanalysisisgetaviewofthetimeseriesplotofallthevariables

    intheanalysis.ToseeaplotofavariablegotoGraphics>>Time-seriesgraphs>>Lineplots.Forthetime

    beingconcentrateonlyonthePlotstabonthepopped-upcommandwindow.ClickontheCreatebutton

    toseeanotherpopped-upcommandwindow.IntheMaintabselecttheTime-seriesplotintheChoosea

    plotcategoryandtypesectionandintheSelecttypedrop-downmenuselectLine.IntheYvariabledrop-

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    3/11

    3

    downmenuselectthevariabletoplotagainsttime.Forexampleselecttheconvariableinourdata

    andthenselectthe Submitbutton.Itmaytakefewsecondstoviewtheplotofthevariable.Theplotof

    theconvariableinourcaselookslikethefollowing:

    Figure:Lineplot

    Thisgraph can alsobegenerated usingthe command interface bywriting twoway(tsline con)inthe

    command window. One can either select Scatter in the Select type drop-down menu or use the

    command interface and write twoway (tsline con, recast(scatter)). The command for line connected

    scatterplotistwoway(tslinecon,recast(connected)).

    Figure:Scatterplot Figure:Lineconnectedscatterplot

    Similargraphsofothervariablescanalsobegeneratedusingthesamecommand.Forexample,forthe

    variablergdppcusethecommandof twoway(tsline rgdppc)forlineplotor twoway(tsline rgdppc,

    recast(connected))forlineconnectedscatterplot.SavethegraphsusingtheSavegraphbuttononthegraphwindowinthedesiredfolder.

    Unit-roottestingforsinglevariable

    Mostofthetimeseriesvariablesarenon-stationary.Tocheckfortheunit-rootinthevariablesthereare

    manyalternatives.However,themostrecommendedmethodsaretheAugmentedDickey-Fuller(ADF

    testandthePhillips-Perron(P-P)test.ToperformtheADFtestgotoStatistics>>Timeseries>>Tests>>

    AugmentedDickey-Fullerunit-roottest.IntheMaintabofthepopped-upwindowselectthevariableto

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    4/11

    4

    testfromthedrop-downmenuof Variable.InthesectionofOptionscheckthedesiredboxestohavein

    the test.For example, ina single variableunit-root testing the box ofSuppress constant term in the

    regressionshouldnotbechecked.Ontheotherhand,theinclusionoftrendand/ordriftterminthe

    regressiondependsonthenatureoftheplotofthevariable.Selectthenumberoflagstoincludethe

    testfromtheLaggeddifferencestab.Therearenocertainrulestoselectthenumberoflags.OnecanuseAkaike'sinformationcriterion(AIC)orSchwarzBayesianinformationcriteriontodeterminethenumber

    oflags.ThereisaruleofthumbthatmanyEconometriciansuseindetermininglags,whichstatesthatif

    thedataisyearlythenuseonlyonelag;ifthedataisquarterly,thenuseatleast4lags,andsimilarlyi

    thedataismonthly,useupto12lags.Inthisguidetestforunit-rootinthevariableofcon,onelaghas

    beenused.Theoutputintheresultwindowlookslikethefollowing:

    Wecanaccomplishthesametaskusingthecommandwindow byusing the commandofdfuller con

    regresslags(1),whichismucheasiertouse.

    TodothePhillips-Perron(P-P)testgotoStatistics>>Timeseries>>Tests>>Phillips-Perronunitroots

    test.IntheMaintabselectconintheVariable:drop-downmenuandselectthe defaultlagsoption

    andthenpressthesubmitbutton.Insteadofthisusethecommandofpperroncontodothesamething

    Theresultwouldlooklikethefollowing:

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    5/11

    5

    Usingthestepsdescribedonecandotheunit-roottestforallthevariablesinthemodelofanalysis.One

    pointshouldbenotedisthattheplotofavariablegivesacluewhethertoincludeatrendintotheunit-

    roottest.Forexample,theplotofrealGDPpercapitaisgivenbelow.

    Theplotclearlyshowsthatthevariablehasabuilt-intrend.So,oneshouldincludethetrendintothe

    test.Inourdataforthevariablergdppc,theoptimaltestresultcomesupwithatrendandwith4lags

    intotheADFtest.Thecommandforthetestisdfullerrgdppc,trendregresslags(4).FortheP-Ptestthe

    commandispperronrgdppc,trend.

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    6/11

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    7/11

    7

    TheresultsshowthatthefirstdifferenceofconisstationaryastheADFteststatistic(-3.093)isgreate

    thanthe5%criticalvalue(-3.000)inabsolutetermsand/ortheMackinnonp-valueoftheP-Pstatisticis

    approximatelyzero.Similarly,usethesamemethodtoshowthatalltheothervariablesarestationaryin

    thefirstdifferencedform.So,thevariablesareintegratedoforderone {I(1)}.Remembertoincludea

    trendtermintotheunit-roottestofthedrgdppcvariable.

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    8/11

    8

    Testingforcointegrationin{I(1)}variables:ErrorCorrectionModel(ECM)

    Using the data one can estimate a linear demand function of cigarettes. In estimating the demand

    functionwithtimeseriesdata,theestimationmethodologyisverycrucial(seeforinstanceHarris,1995)

    Themajorconcernwiththetimeseriesisthatifnon-stationarityofdataseriespersiststhenitmayleadtospuriousrelationship.Toavoidthisproblem,itisnecessarytousethecointegrationmethodology.The

    regressionequationcanbeestimatedfortheperiodof1981to2004usingtheEngel-Granger(E-G)two-

    step procedure (Engel and Granger, 1987). The first step is to estimate a long-run equation using

    ordinaryleastsquares(OLS)withvariables,whichareintegratedoforderone, I(1),intheirlevels.In

    ordertoavoidspuriousregression,residualbasedcointegrationtestcanbeused,wherethestationarity

    oftheresidualimpliesaconintegratingrelationshipamongthevariablesinthelongrunequation.The

    secondstepoftheE-Gprocedureistoestimatethecorrespondingerror-correctionmodel(ECM),based

    onthelongruncointegratingrelationshiptoobservetheshortrundynamics(EngelandGranger,1987).

    OnecanestimateanECMusingtheresidualfromthelong-runequation.TheECMisbasedonstationary

    data(asalltheI(1)regressorsareinfirstdifferenceform)andincludesthelaggedresidualsofthelongrunequation,whichisalsoI(0)whenthevariableshavecointegratingrelationship.Onethingyoushould

    know is that the dummy variables are not continuous. As a result, you need not worry about the

    stationarityofthedummyvariables.Thetwodummyvariablesfortheyearof1993and1995arehereto

    controlfortheunusualtroughandspikesrespectivelyintheconsumptiondata.

    ThefirststepoftheE-GistorunanOLSregressiononthevariablesintheirlevels.Thecommandforthe

    regressionisregconrelprcrgdppcdum93dum95.

    Togettheresidualfromthisregressionwecanusethecommandof predictresid,r,whereresidisthe

    variablenameofthepredictedresidual.Theunit-rootoftheresidualcanbetestedbyADFand/orP-P

    test.However,onemustrememberthatinthiscaseyouhavetocheckforthenoconstantterminthe

    regressionoptionandthecriticalvaluesshouldbecalculatedusingtheMacKinnonsresponsesurface

    analysistable(Mackinnon,1991).ThecommandfortheADFtestforresidualis dfullerresid,noconstant

    regresslags(3)andfortheP-Ptestispperronresid,noconstantregress.

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    9/11

    9

    The MacKinnon critical values for the cointegrating equation of 3 variables without trend using 24

    observations at1%,5%and 10% levelofsignificance are -4.954, -4.114, and -3.717 respectively. The

    Dickey-Fuller critical values for this regression at 1%, 5%, and 10% level are -2.66, -1.95, and -1.60

    respectively.So,onecanclearlyseethattheMacKinnoncriticalvaluesaremuchhigherthantheDickey-

    Fullercriticalvalues.AsaresultusingtheD-Fcriticalvaluescanleadtoerrorinstatisticalanalysis.

    OnecanseethattheADFteststatistic(-2.947)islowerthantheMacKinnoncriticalvalueevenat10%level.So,usingADFtestonecannotsaythattheresidualfromtheregressionisstationary.However,the

    P-Pteststatistic(-4.406)ishigherthantheMacKinnoncriticalvalueat5%level.So,itshowsthatthe

    residual is stationary.Considering the fact that asDittmann(2002) argued,Phillips-Perrontest when

    appliedtoresidualbasedconintegrationdeterminationaremorepowerfulthantheADFtest,onecan

    arguethatthereexistsacointegratingrelationshipinthelong-rundemandequationofcigarettes.

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    10/11

    10

    Onecanrunashortrunerrorcorrectionmodel(ECM).IntheECM,theoneperiodlaggedresidualfor

    annualdataactsastheerrorcorrectionterm.Toget theoneperiod lagged residualonecanuse the

    commandasgenlagresid=resid[_n-1].

    ThecommandfortheECMinthiscaseisregdcondrelprcdrgdppcddum93ddum95lagresid.

  • 8/7/2019 Brief Introduction to Stata 10 Time Analysis

    11/11

    11

    References:

    IngolfDittmann(2002):Residual-BasedTestsforFractionalCointegration:AMonteCarloStudy,Journal

    ofTimeSeriesAnalysis,Volume21Issue6,Pages615647.

    JamesMacKinnon(1991):CriticalValuesforCointegrstionTests,inR.EngelandC.Granger,Long-run

    EconomicRelationships,OxfordUniversityPress.Richard I. D. Harris (1995): Using Cointegration analysis in Econometric Modelling, FT Prentice Hal

    Publication.

    RobertAngelandCliveGranger(1987):Cointegrationanderrorcorrection:Representation,estimatio

    andtesting,Econometrica,55:251-276.

    Appendix:Thedatasetusedforthistutorial:

    year con relprc rgdppc dum93 dum95 trend

    1981 754.15 12.54 10273.60 0 0 1

    1982 788.90 13.59 10322.57 0 0 2

    1983 701.55 13.24 10518.93 0 0 3

    1984 735.55 14.83 10832.18 0 0 4

    1985 719.65 15.30 10951.98 0 0 5

    1986 718.25 15.91 11199.04 0 0 6

    1987 738.10 16.47 11376.67 0 0 7

    1988 701.55 17.27 11408.75 0 0 8

    1989 704.40 16.20 11473.76 0 0 9

    1990 614.45 19.83 11797.61 0 0 10

    1991 680.20 17.89 11938.95 0 0 11

    1992 625.80 16.76 12286.00 0 0 12

    1993 575.80 17.34 12724.48 1 0 13

    1994 632.75 17.20 12994.34 0 0 14

    1995 868.95 16.10 13381.83 0 1 15

    1996 811.10 15.36 13768.54 0 0 16

    1997 930.05 14.69 14297.28 0 0 17

    1998 994.45 15.49 14815.08 0 0 18

    1999 977.90 16.66 15315.05 0 0 19

    2000 986.60 15.74 15997.47 0 0 20

    2001 1006.00 15.59 16607.80 0 0 21

    2002 1019.20 15.08 17117.09 0 0 22

    2003 1124.95 14.70 17773.69 0 0 23

    2004 1151.25 14.06 18504.51 0 0 24

    Note:

    Thetheoreticalpremiseandmethodologyusedinthistutorialisforillustrativepurposesonly.

    AdditionalResources

    QuestionspertainingtoStata-10forTimeSeriesAnalysiscanbesubmittedtoNYUsDataServiceStudio

    [email protected].