Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: ST: simple date question


From   "Sergiy Radyakin" <[email protected]>
To   [email protected]
Subject   Re: st: ST: simple date question
Date   Mon, 14 Jan 2008 18:49:15 -0500

Dear Dr. Uslaner,

there are a lot of ways this can be achieved. If your data refers only
to April and October, than you can write your dates as "2000 October"
and "2001 April".
(strings) and sort by this variable (it will be ok since
"April"<"October"). But make sure that you are consistent with spaces
(in your example you write "October 2003" with a space, and in other
dates not -- this will matter). If you have two variables, one holding
a month, another holding a year, you can concatenate them:

gen mydate=year+month

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if both year and month are stored as strings


gen mydate=string(year)+month
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ if year is stored as a number and month
is stored as a string


gen mydate=year*12+month
^^^^^^^^^^^^^^^^^^^^^^^^^^^ if both year and month are stored as numbers.

If your original data comes with one or more variables holding dates,
then what is the format there?

It is sometimes convinient to represent dates as number of days
(months, quarters, etc, in your case half-years) from a particular
start (not necessarily year 0 A.D.) So if the earliest date in your
dataset is October 2000, you could recode your data to be:
1 = October 2000
2 = April 2001
....

And then define labels, so that you see the values nicely on your screen.

I am sure you will also receive a dozen of other suggestions from
other Statalist users.

Best regards,
    Sergiy Radyakin







On 1/14/08, Eric Uslaner <[email protected]> wrote:
> I've been trying to convert seven numbers to dates (without having done this before).  I've read the help, the manual, and several tutorials and I can't get past the obscure language so that I can create a variable that I can use on the LHS of a graph hbar command.
>
> I have created new variables for month and year (and even a fake one for day).  All I want is a date variable that will be sorted in this order:
>
> October2000
> April2001
> October2001
> April2002
> October2002
> April2003
> October 2003
>
> I've spent an hour on this with no success.  I know that it can't be too difficult, but the manual (and the on-line help).  Thanks in advance.
>
> Ric
>
>
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index