Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: RE: foreach question


From   David Torres <torresd@umich.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: foreach question
Date   Sun, 22 Aug 2010 16:23:42 -0400

Thanks, Martin,

You guys make it look so easy.

Cheers,
D

Quoting Martin Weiss <martin.weiss1@gmx.de>:


<>

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


***********
clear*

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

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

HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David Torres
Sent: Sonntag, 22. August 2010 21:55
To: statalist@hsphsun2.harvard.edu
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

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index