Statalist


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

Re: st: ST: simple date question


From   "Joseph Coveney" <[email protected]>
To   "Statalist" <[email protected]>
Subject   Re: st: ST: simple date question
Date   Tue, 15 Jan 2008 11:05:01 +0900

Eric Uslaner 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

--------------------------------------------------------------------------------

The do-file below will get you the dates.  See the FAQ at
www.stata.com/support/faqs/graphics/nicedate.html for axis labeling.

Joseph Coveney

clear *
set more off
set obs 7
generate str month = "October" if mod(_n, 2)
replace month = "April" if missing(month)
generate int year = month == "April"
replace year = sum(year)
replace year = year + 2000
generate int date = date(string(year) + " " + month + " 01", "YMD")
format date %tdm-CY
list, clean
generate byte x = _n
graph hbar (asis) date, over(x)
exit


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