Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Re: define variable to be date
From
"Joseph Coveney" <[email protected]>
To
<[email protected]>
Subject
st: Re: define variable to be date
Date
Mon, 18 Jun 2012 09:38:36 +0900
Philipp Braunfels wrote:
I reshaped my panel-dataset from wide to long format and now have a variable
called "month" that serves as date variable in my dataset (covering 10 years).
Now I want to run the <xtset> command but apparently "month" is not identified
as date variable by stata (current type is "float"). The variable Month looks as
follows:
Month
12001
22001
32001
...
112001
122001
12002
...
I looked at the stata archive but still cannot figure out how I can tell stata
that the values (e.g. 12001) are supposed to be dates (e.g. Jan 2001). I tried
the command - gen date = date(month, "MY") - but I am returned "(r 109) "type
mismatch". I would appreciate any help on this issue.
--------------------------------------------------------------------------------
Something like that below would work. Suggestion: adopt ISO 8601.
Joseph Coveney
input byte panel long Month
1 12001
1 22001
1 32001
2 112001
2 122001
2 12002
end
*
* Begin here
*
tostring Month, generate(panel_date)
generate int month = ///
(real(substr(panel_date, -4, 4)) - 1960) * 12 - 1 + ///
real(substr(panel_date, 1, length(panel_date)-4))
xtset panel month, format(%tm)
list panel ?onth, noobs sepby(panel)
exit
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/