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]

Re: st: foreach question


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: foreach question
Date   Sun, 22 Aug 2010 15:10:05 -0500

One way would be to use Jeffrey Arnold's -sortrows- (-ssc desc sortrows-):

clear
input str10 d1     str10  d2 str10  d3 str10  d4
23July1997    01Jan1997     12Sept1997     03Feb1997
end

forv i = 1/4  {
	gen date`i' = date(d`i', "DMY")
	format date`i' %td
}
drop d1-d4
sortrows date1-date4,replace
l


Scott


On Sun, Aug 22, 2010 at 2:54 PM, David Torres <[email protected]> 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/


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