Bookmark and Share

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]

Re: st: Re: define variable to be date


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Re: define variable to be date
Date   Mon, 18 Jun 2012 09:19:16 +0100

/// indicates end-of-line. It is only to be typed if it is needed to
indicate end-of-line in a do-file, do-file editor or program. Joseph
was signalling that what he typed was all one command.

You were right to guess that /// might be problematic, but why not try
omitting it to see what happens?

Also, you had two solutions; you could have tried the other one.

To reply to a Statalist posting, all you need do is reply directly in
your mailer. No one wants two copies.

Nick

On Mon, Jun 18, 2012 at 8:27 AM, Braunfels, Philipp (Stud. SBE /
Alumni) <[email protected]> wrote:
> Hello, thanks a lot for the promt response.
> I tried to implement Joseph code:
>
>> 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
>
> but the "generate int month" does not work (my date variable name is "Month" with a capital letter). It returns the error "invalid syntax". Is it correct that I really write " = ///"  ? or I am supposed to subsitute something for the ///?
>
> Best,
> Philipp
>
> PS. is it correct to just click on reply, or do I have to put anyone in the CC or BCC?, or just write the mail to [email protected]
> ________________________________________
> Von: [email protected] [[email protected]] im Auftrag von Nick Cox [[email protected]]
> Gesendet: Montag, 18. Juni 2012 03:14
> An: [email protected]
> Betreff: Re: st: Re: define variable to be date
>
> Philipp's approach is based on the assumption that -date()- can
> produce monthly dates from what is apparently a numeric argument, but
> that is mistaken in two key respects. First, -date()- produces only
> daily dates; it goes back to a period when those were the only dates
> handled by Stata. Second, -date()- requires a string argument, hence
> the error message. All but the history behind that is evident from
> close study of the help for -dates and times-.
>
> In addition to Joseph's solution, another is
>
> gen panel_date = ym(mod(Month, 10000), floor(Month/10000))
>
> With dates in Philipp's form, the year is the remainder on dividing by
> 10000 and the month is obtained by dividing by 10000 and rounding
> down. As in Joseph's careful code, you would want to format the
> monthly date.
>
> Nick
>
> On Mon, Jun 18, 2012 at 1:38 AM, Joseph Coveney <[email protected]> wrote:
>
> Joseph Coveney
>
>> 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
>
> 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.

*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index