Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Reformatting all dates in a Stata dataset

From   Nick Cox <>
To   "''" <>
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. 


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


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


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

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


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:

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