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]

st: RE: Combining dates in Stata


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Combining dates in Stata
Date   Thu, 26 Jan 2012 20:35:51 +0000

-help dates and times- explains this. 

You can create a new monthly variable by 

gen modate = ym(year, month) 
format %tm 

I can do this interactively like this on individual numbers 

. di ym(2012,1)
624

. di %tm ym(2012,1)
 2012m1

Evidently you need to -format- your date variable to make it easily intelligible. I've just shown the laziest format and there are others. 

Don't get rid of the original year and month variables. They are likely to remain useful for many purposes. 

Nick 
n.j.cox@durham.ac.uk 

natasha agarwal

I have two time variables in my dataset - one for year and one for month.

Both of these variables are numeric with Year containing four-digit
year values and month is a two-digit values ranging from 1 to 12.

I would like to combine the Year and month variables into one a time
variable to allow me to work with the dataset as a panel. How do I
recode (or replace) the Year and Semester month to create one.

Specifically, I would like to have one variable that reads 1/2000 for
january 2000, or 2000m1... I do not really mind the format!


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