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: foreach question

From   "Martin Weiss" <>
To   <>
Subject   st: RE: foreach question
Date   Sun, 22 Aug 2010 22:06:35 +0200


All a bit unwieldy, b/c your data are in a format that Stata is not
particularly fond of:


inp str10(Date1 Date2 Date3 Date4)
23July1997 01Jan1997 12Sept1997 03Feb1997

gen byte id=1
reshape long Date, i(id) j(number)

gen newdate=date(Date, "DMY")
sort newdate
drop newdate
replace number=_n
reshape wide
drop id
list, noo

Certainly this is not a task for a loop...


-----Original Message-----
[] On Behalf Of David Torres
Sent: Sonntag, 22. August 2010 21:55
Subject: st: foreach question

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


David Diego Torres

*   For searches and help try:

*   For searches and help try:

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