Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Martin Weiss" <martin.weiss1@gmx.de> |
To | <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: foreach question |
Date | Sun, 22 Aug 2010 22:33:26 +0200 |
<> *** ds foreach v in `r(varlist)' { *** could be just *********** foreach var of varlist *{ *********** HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Eric Booth Sent: Sonntag, 22. August 2010 22:08 To: <statalist@hsphsun2.harvard.edu> Subject: Re: st: foreach question <> I think this is what you are asking: ******! clear inp str12(Date1 Date2 Date3 Date4) 23July1997 01Jan1997 12Sept1997 03Feb1997 05July1997 04July1997 03July1997 02July1997 end ds foreach v in `r(varlist)' { g `v'2 = date(`v', "DMY") format `v'2 %td drop `v' rename `v'2 `v' } g id = _n reshape long Date, i(id) j(n) sort Date g new = _n drop n id g id = 1 reshape wide Date, i(id) j(new) drop id li ******! ~ Eric __ Eric A. Booth Public Policy Research Institute Texas A&M University ebooth@ppri.tamu.edu Office: +979.845.6754 On Aug 22, 2010, at 2:54 PM, David Torres wrote: > Is there a way to sort or reorder dates using the foreach command--perhaps using the egen function in the loop or something? > > How do I get: > > Date1 Date2 Date3 Date4 > > 23July1997 01Jan1997 12Sept1997 03Feb1997 > > to be ordered thusly: > > Date1 Date2 Date3 Date4 > 01Jan1997 03Feb1997 23July1997 12Sept1997 > > Thanks, > > -- > David Diego Torres > > * > * 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/ * * 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/ * * 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/