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: Reformatting all dates in a Stata dataset


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Reformatting all dates in a Stata dataset
Date   Wed, 2 Feb 2011 11:15:34 +0000

Here are three ways to do it. 

1. 

foreach v of var * { 
	if "`: format `v''" == "%tc" format `v' %td
}

2.

ds, has(format %tc)
format `r(varlist)' %td 

3. 

findname, format(%tc)
format `r(varlist)' %td 

-findname- is from SJ. See also help for -extended_fcn-. 

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

James Morden

I am importing lots of datasets from Access into Stata using the odbc command. The automatic format of all my dates after I have imported the dataset is %tc which includes date and time. I would ideally like all my dates to be %td, i.e just date. Does anyone know of a command that would go through my variables one by one and say if format = %tc, reformat as %td.

I have tried to find a way of referring to the format tag attached to each variable but have not managed this so far. I am using Stata 10.


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