Example: confidence

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

Declare data to be panel dataSyntaxMenuDescriptionOptionsRemarks and examplesStored resultsAlso seeSyntaxDeclare 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 periodicity oftimevarnoquerysuppress summary calculations and outputnoqueryis not shown in the dialog (default)timevar s units to be obtained fromtimevar s display formatclocktimetimevaris%tc: 0=1jan1960 00:00 , 1=1jan1960 00:00 ,..dailytimevaris%td: 0=1jan1960, 1=2jan1960.

Statistics > Longitudinal/panel data > Setup and utilities > Declare dataset to be panel data Description xtset declares the data in memory to be a panel. You must xtset your data before you can use the other xt commands. If you save your data after xtset, the data will be remembered to be a panel and you will not have to xtset again.

Tags:

  Data, Panels, Panel 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 dataSyntaxMenuDescriptionOptionsRemarks and examplesStored resultsAlso seeSyntaxDeclare 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 periodicity oftimevarnoquerysuppress summary calculations and outputnoqueryis not shown in the dialog (default)timevar s units to be obtained fromtimevar s display formatclocktimetimevaris%tc: 0=1jan1960 00:00 , 1=1jan1960 00:00 ,..dailytimevaris%td: 0=1jan1960, 1=2jan1960.

2 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 xtset Declare data to be panel datadeltaoptionspecifies 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)

3 Allowed units for%tcand%tCtimevarsareseconds secs secminutes mins minhours hourdays dayweeks weekand for all other%ttimevarsaredays dayweeks weekMenuStatistics>Longitudinal/ panel data >Setup and utilities> Declare dataset to be panel dataDescriptionxtsetdeclares the data in memory to be a panel . You mustxtsetyour data before you can usethe other xt commands. If yousaveyour data afterxtset, the data will be remembered to be apanel and you will not have 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.

4 For instance,panelvarmight be country and the observationswithin might be the second syntax xtsetpanelvar timevar the data are to be a panel and the order ofobservations within panel are considered ordered bytimevar. For instance, in data collected fromrepeated surveying of the same people over various years,panelvarmight be person andtimevar, you specifytimevar, you may then use Stata s time-series operators such (lag andlead) in other commands. The operators will be interpreted as lagged and lead values within arguments xtset displays how the data are currentlyxtset. If the data are setwith apanelvarand atimevar,xtsetalso sorts the data bypanelvar timevar.

5 If the data are setwith apanelvaronly, the sort order is not , clearis a rarely used programmer s command to Declare that the data are no longer tobe considered a Declare data to be panel data 3 Optionsunitoptionsclocktime,daily,weekly ,monthly,quarterly,halfyearly,yearly,gen eric,andformat(%fmt)specify the units in whichtimevaris recorded, iftimevaris often simply be a variable that counts 1, 2,.., and is to be interpreted as first yearof survey, second year,.., or first month of treatment, second month,.. In these cases, youdo not need to specify other cases,timevarwill be a year variable or the like such as 2001, 2002.

6 , and is to beinterpreted as year of survey or the like. In those cases, you do not need to specify still other, more complicated cases,timevarwill be a full-blown%tvariable; see [D] 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)Understand thattimevaris not required to be a%tvariable; it can be any variable of your ownconcocting so long as it takes on integer values.

7 When youxtseta time variable that is not%t, the display format does not change unless you specify theunitoptiongenericor use theformat() ()specifies the periodicity oftimevarand 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 you specifieddelta(2), then attimevar=5, the previous time would betimevar=5 2=3and the next time would betimevar=5+2=7.

8 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 periodicity. Theunitoptionsset the ()sets the periodicity. You are not required to specify one to specify the other. You mighthave a generictimevarbut it counts in 12: 0, 12, 24,.. You would skip specifyingunitoptionsbut would specifydelta(12).

9 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).

10 4 xtset Declare data to be panel dataWhen 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 .


Related search queries