Example: confidence

Title stata.com xtset — Declare data to be panel data

Declare data to be panel dataDescriptionQuick startMenuSyntaxOptionsRemarks and examplesStored resultsAlso seeDescriptionxtsetmanages the panel settings of a dataset. You mustxtsetyour data before you can usethe the data in memory to be a panel in which theorder of observations is timevardeclares the data to be a panel in whichthe order of observations is relevant. When you specifytimevar, you can then use Stata s time-seriesoperators and analyze your data with thetscommands without having totssetyour arguments displays how the data are currentlyxtset. If the data are set with apanelvarand atimevar,xtsetalso sorts the data bypanelvar timevarif atimevarwas specified.

to use the xt commands. You do not need to set both, but it will not matter if you do. xtset and tsset are different, however, when you set just a panelvar—you type xtset panelvar— or when you set just a timevar—you type tsset timevar. If you save your data after xtset, the data will be remembered to be a panel and you will not

Tags:

  Data

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of Title stata.com xtset — Declare data to be panel data

1 Declare data to be panel dataDescriptionQuick startMenuSyntaxOptionsRemarks and examplesStored resultsAlso seeDescriptionxtsetmanages the panel settings of a dataset. You mustxtsetyour data before you can usethe the data in memory to be a panel in which theorder of observations is timevardeclares the data to be a panel in whichthe order of observations is relevant. When you specifytimevar, you can then use Stata s time-seriesoperators and analyze your data with thetscommands without having totssetyour arguments displays how the data are currentlyxtset. If the data are set with apanelvarand atimevar,xtsetalso sorts the data bypanelvar timevarif atimevarwas specified.

2 Ifthe data are set with apanelvaronly, the sort order is not , clearis a rarely used programmer s command to Declare that the data are no longer tobe considered a startDeclare dataset to be panel data with panel identifierpvarxtset pvarIndicate that observations are ordered by year, stored intvar1xtset pvar tvar1As above, but indicate that observations are instead made every 2 yearsxtset pvar tvar1, delta(2)Indicate that observations are made monthly;tvar2is not formattedxtset pvar tvar2, monthlyAs above, and apply%tmformat totvar2xtset pvar tvar2, format(%tm)MenuStatistics>Longitudinal/p anel data >Setup and utilities> Declare dataset to be panel data12 xtset Declare data to be panel dataSyntaxDeclare data to be panelxtsetpanelvarxtsetpanelvar timevar[,tsoptions]Display how data are currently xtsetxtsetClear xt settingsxtset, clearIn the Declare syntax,panelvaridentifies the panels and the optionaltimevaridentifies the timeswithin units oftimevardeltaoptionspecify length of period oftimevarnoquerysuppress summary calculations and outputcollectis allowed.

3 See[U] Prefix not shown in the dialog (default)timevar s units fromtimevar s display formatclocktimetimevaris%tc: 0=1jan1960 00:00 , 1=1jan1960 00:00 ,..dailytimevaris%td: 0=1jan1960, 1=2jan1960,..weeklytimevaris%tw: 0=1960w1, 1=1960w2,..monthlytimevaris%tm: 0=1960m1, 1=1960m2,..quarterlytimevaris%tq: 0=1960q1, 1=1960q2,..halfyearlytimevaris%th: 0=1960h1, 1=1960h2,..yearlytimevaris%ty: 1960=1960, 1961=1961,..generictimevaris%tg: 0=?, 1=?,..format(%fmt)specifytimevar s format and then apply default ruleIn all cases, negativetimevarvalues are Declare data to be panel data 3deltaoptionspecifies the period between observations intimevarunits and may be specified asdeltaoptionExampledelta(#) delta(1)ordelta(2)delta((exp)) delta((7*24))delta(# units) delta(7 days)ordelta(15 minutes)ordelta(7 days 15 minutes)delta((exp)units) delta((2+3) weeks)

4 Allowed units for%tcand%tCtimevarsareseconds second secs secminutes minute mins minhours hourdays dayweeks weekand for all other%ttimevarsaredays dayweeks weekOptionsunitoptionsclocktime,daily,we ekly,monthly,quarterly,halfyearly,yearly ,generic,andformat(%fmt)specify the units in whichtimevaris usually be a variable that counts 1, 2,.., and is to be interpreted as first year ofsurvey, second year,.., or first month of treatment, second month,.. In these cases, you donot need to specify other cases,timevarwill be a year variable or the like such as 2001, 2002,.., and is to beinterpreted as year of survey or the like.

5 In those cases, you do not need to specify other, more complicated cases,timevarwill be a full-blown%tvariable; see [D]Datetime. Iftimevaralready has a%tdisplay format assigned to it, you do not need to specify aunitoption;xtsetwill obtain the units from the format. If you have not yet bothered to assign the appropriate%tformat to the%tvariable, however, you can use theunitoptionsto tellxtsetthe units. Thenxtsetwill settimevar s display format for you. Thus, theunitoptionsare convenience options;they allow you to skip formatting the time variable. The following all have the same net result:Alternative 1 Alternative 2 Alternative 3format t %td(t not formatted)(t not formatted) xtset pid t xtset pid t, daily xtset pid t, format(%td)timevaris not required to be a%tvariable; it can be any variable of your own concocting so longas it takes on only integer values.

6 When youxtseta time variable that is not%t, the displayformat does not change unless you specify theunitoptiongenericor use theformat() ()specifies the period between observations intimevarand is commonly used whentimevaris% ()is only sometimes used with the other%tformats or with generic time ()is not specified,delta(1)is assumed. This means that attimevar=5, the previoustime istimevar=5 1=4 and the next time would betimevar=5+1=6. Lag and leadoperators, for instance, would work this way. This would be assumed regardless of the units xtset Declare data to be panel dataIf you specifieddelta(2), then attimevar=5, the previous time would betimevar=5 2=3and the next time would betimevar=5+2=7.

7 Lag and lead operators would work this the observation withtimevar=5, be the value ofincomein the observationfor whichtimevar=3 be the value ofincomein the observation forwhichtimevar=7. If you then add an observation withtimevar=4, the operators will still workappropriately; that is, attimevar=5, still have the value ofincomeattimevar= are two aspects oftimevar: its units and its length of period. Theunitoptionsset the ()sets the length of period. You are not required to specify one to specify the other. Youmight have a generictimevarbut it counts in 12: 0, 12, 24,.. You would skip specifyingunitoptionsbut would specifydelta(12).

8 We mentioned thatdelta()is commonly used with%tctimevarsbecause Stata s%tcvariableshave units of milliseconds. Ifdelta()is not specified and in some model you refer ,you will be referring to the value ofbp1 ms ago. Few people have data with periodicity of amillisecond. Perhaps your data are hourly. You could specifydelta(3600000). Or you couldspecifydelta((60*60*1000)), becausedelta()will allow expressions if you include anextra pair of parentheses. Or you could specifydelta(1 hour). They all mean the same thing:timevarhas periodicity of 3,600,000 ms. In an observation for whichtimevar=1,489,572,000,000(correspon ding to 15mar2007 10:00:00), be the observation for whichtimevar=1,489,572,000,000 3,600,000=1,489,568,400,000 (corresponding to 15mar2007 9:00:00).

9 When youxtsetthe data and specifydelta(),xtsetverifies that all the observations followthe specified periodicity. For instance, if you specifieddelta(2), thentimevarcould contain anysubset of{.., 4, 2,0,2,4,..}or it could contain any subset of{.., 3, 1,1,3,..}. Iftimevarcontained a mix of values,xtsetwould issue an error message. The check is made oneach panel independently, so one panel might containtimevarvalues from one set and the next,another, and that would be used inxtset, clear makes Stata forget that the data ever werextset. This is a rarelyused programmer s following option is available withxtsetbut is not shown in the dialog box:noquerypreventsxtsetfrom performing most of its summary calculations and suppresses this option, only the following results are posted:r(tdelta) r(tsfmt)r(panelvar) r(unit)r(timevar) r(unit1)Remarks and the dataset in memory to be panel data .

10 You need to do this before you can usethe otherxtcommands. The storage types of bothpanelvarandtimevarmust be numeric, and bothvariables must contain integers are two syntaxes for setting the data :xtsetpanelvarxtsetpanelvar timevarIn the first syntax xtsetpanelvar the data are set to be a panel and the order of the observationswithin panel is considered to be irrelevant. For instance,panelvarmight be country and the observationswithin might be Declare data to be panel data 5In the second syntax xtsetpanelvar timevar the data are to be a panel and the order ofobservations within panel are considered ordered bytimevar.


Related search queries