📄 tsset.hlp
字号:
{smcl}
{* 08mar2005}{...}
{cmd:help tsset}{right:dialog: {bf:{dialog tsset}}}
{hline}
{title:Title}
{p2colset 5 19 21 2}{...}
{p2col :{hi:[TS] tsset} {hline 2}}Declare a dataset to be time-series
data{p_end}
{p2colreset}{...}
{title:Syntax}
{pstd}Declare data to be time series and specify the time variable
{p 8 15 2}
{cmd:tsset} [{it:panelvar}] {it:timevar} [{cmd:,} {it:options}]
{pstd}Display how dataset is currently tsset
{p 8 15 2}
{cmd:tsset}
{pstd}Clear time-series settings
{p 8 15 2}
{cmd:tsset, clear}
{pstd}
where {it:panelvar} is a variable that identifies the panels and {it:timevar}
is a variable that identifies the time periods.
{synoptset}{...}
{synopthdr:options}
{synoptline}
{synopt :{opt d:aily}}display time scales as daily
{bind:({cmd:%td}, 0 = 1jan1960)}{p_end}
{synopt :{opt w:eekly}}display time scales as weekly
{bind:({cmd:%tw}, 0 = 1960w1)}{p_end}
{synopt :{opt m:onthly}}display time scales as monthly
{bind:({cmd:%tm}, 0 = 1960m1)}{p_end}
{synopt :{opt q:uarterly}}display time scales as quarterly
{bind:({cmd:%tq}, 0 = 1960q1)}{p_end}
{synopt :{opt h:alfyearly}}display time scales as half-yearly
{bind:({cmd:%th}, 0 = 1960h1)}{p_end}
{synopt :{opt y:early}}display time scales as yearly
{bind:({cmd:%ty}, 0 = 1960 = 1960)}{p_end}
{synopt :{opt g:eneric}}display time scales as generic
{bind:({cmd:%tg}, 0 = ?)}{p_end}
{synopt :{opth f:ormat(%fmt)}}indicate how {it:timevar} will be
displayed{p_end}
{synoptline}
{p2colreset}{...}
{title:Description}
{pstd}
{cmd:tsset} declares the data to be a time series and designates that
{it:timevar} represents time. Stata's time-series operators then use
{it:timevar} in computing operations on variables.
{pstd}
{cmd:tsset} without arguments displays how the dataset is currently
{cmd:tsset} and sorts the data on {it:timevar} or
{it:panelvar timevar} if it is sorted differently from that.
{pstd}
{cmd:tsset, clear} is a rarely used programmer's command to declare that
the data are no longer a time series.
{title:Options}
{phang}
{cmd:daily}, {cmd:weekly}, {cmd:monthly}, {cmd:quarterly}, {cmd:halfyearly},
{cmd:yearly}, {cmd:generic}, and {opth format(%fmt)}, indicate how {it:timevar}
will be displayed{hline 2}which {cmd:%t} format, if any, will be placed on
{it:timevar}. Whether {it:timevar} is formatted is optional; all {cmd:tsset}
requires is that {it:timevar} take on integer values.
{pmore}
The optional format states how {it:timevar} is measured (for instance,
{it:timevar} = 5 might mean the fifth day of January 1960, or the fifth week of
January 1960, or the fifth something else) and how you want it displayed
({it:timevar} = 5 might be displayed 05jan1960, 1960-5, or in a host of other
ways.) In addition, the format makes the {cmd:tin()} and {cmd:twithin()}
selection functions work so that later, after {cmd:tsset}ing the data, you can
type things like
{bind:{cmd:regress} ... {cmd:if tin(1jan1998, 1apr1998)}} to run the
regression on the subsample
{bind:1jan1998 {ul:<} {it:timevar} {ul:<} 1apr1998}.
{pmore}
You set the format by placing a {cmd:%t} format on {it:timevar}. You
can do it yourself, or {cmd:tsset} can do it.
{pmore}
The time scales {cmd:%t} understands are daily
{bind:({cmd:%td}, 0 = 1jan1960)}, weekly {bind:({cmd:%tw}, 0 = 1960w1)},
monthly {bind:({cmd:%tm}, 0 = 1960m1)}, quarterly
{bind:({cmd:%tq}, 0 = 1960q1)}, half-yearly {bind:({cmd:%th}},
{bind:0 = 1960h1)}, yearly {bind:({cmd:%ty}, 1960 = 1960)},
and generic {bind:({cmd:%tg}, 0 = ?)}.
{pmore}
Say that {it:timevar} is recorded in Stata quarterly units, meaning
{bind:0 = 1960q1}, {bind:1 = 1960q2}, etc. (Perhaps your data start in
1990q1; then the first observation has {it:timevar} = 120.) You could format
{it:timevar} and then {cmd:tsset} your data.
{p 12 12 2}{cmd:. format} {it:timevar} {cmd:%tq}{p_end}
{p 12 12 2}{cmd:. tsset} {it:timevar}{p_end}
{pmore}
or you could {cmd:tsset} your data and then format {it:timevar},
{p 12 12 2}{cmd:. tsset} {it:timevar}{p_end}
{p 12 12 2}{cmd:. format} {it:timevar} {cmd:%tq}{p_end}
{pmore}
or you could {cmd:tsset} your data specifying {cmd:tsset}'s {cmd:format()}
option,
{p 12 12 2}{cmd:. tsset} {it:timevar}{cmd:, format(%tq)}{p_end}
{pmore}
or you could {cmd:tsset} your data specifying {cmd:tsset}'s {cmd:quarterly}
option,
{p 12 12 2}{cmd:. tsset} {it:timevar}{cmd:, quarterly}{p_end}
{pmore}
These alternatives yield the same result; use whichever appeals to you. See
{help dates} and {help tfmt} for more information on the {cmd:%t} format
and the advantages of setting it.
{phang}
{opt clear} declares that the data are no longer a time series; this is a
rarely used programmer's option.
{title:Examples}
{pstd}
For a generic time series with no specific time scale:
{cmd:. tsset timevar}
{pstd}
For an annual time series:
{p 8 12 2}{cmd:. tsset yearvar, yearly}
{pstd}
For a monthly time series:
{p 8 12 2}{cmd:. tsset movar, monthly}
{pstd}
or, equivalently:
{p 8 12 2}{cmd:. format movar %tm}{p_end}
{p 8 12 2}{cmd:. tsset movar}{p_end}
{pstd}
or still equivalently:
{p 8 12 2}{cmd:. tsset movar, format(%tm)}
{pstd}
or with a pretty format:
{p 8 12 2}{cmd:. tsset movar, fmt(%tmM,_Y)}
{pstd}
which is equivalent to
{p 8 12 2}{cmd:. format movar %tmM,_Y}{p_end}
{p 8 12 2}{cmd:. tsset movar}
{pstd}
For annual panel data:
{p 8 12 2}{cmd:. tsset panelid yearvar, yearly}
{title:Also see}
{psee}
Manual: {bf:[TS] tsset}
{psee}
Online: {helpb tsfill}{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -