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: Arrays and loops for Stata


From   Phil Clayton <philclayton@internode.on.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Arrays and loops for Stata
Date   Fri, 13 Apr 2012 10:57:58 -0400

You can use egen here:
egen firstd=rowmin(disp_date0-disp_date14)
egen lastd=rowmax(disp_date0-disp_date14)

Phil

On 13/04/2012, at 10:48 AM, Hitesh Chandwani wrote:

> Hello all,
> 
> I'm using a dataset that I changed from long to wide using -reshape-.
> What I need to do is for Stata to run a loop that picks out the first
> date that a patient got a prescription from the variables
> disp_date0-disp_date14. I also need to run a loop that picks out the
> last date that the patient got a prescription. I figured out the long
> and crude way of doing this (given below) but would really appreciate
> it if someone could help me with the loop command.
> "disp_date0-disp_date14" are in chronological order.
> 
> ***generate first date of dispensing drug***
> gen firstd=disp_date0
> replace firstd=disp_date1 if firstd==.
> 
> ***generate last date of dispensing drug***
> gen lastd=disp_date14
> replace lastd=disp_date13 if lastd==.
> replace lastd=disp_date12 if lastd==.
> replace lastd=disp_date11 if lastd==.
> replace lastd=disp_date10 if lastd==.
> replace lastd=disp_date9 if lastd==.
> replace lastd=disp_date8 if lastd==.
> replace lastd=disp_date7 if lastd==.
> replace lastd=disp_date6 if lastd==.
> replace lastd=disp_date5 if lastd==.
> replace lastd=disp_date4 if lastd==.
> replace lastd=disp_date3 if lastd==.
> replace lastd=disp_date2 if lastd==.
> replace lastd=disp_date1 if lastd==.
> replace lastd=disp_date0 if lastd==.
> 
> Thanks and regards,
> -- 
> Hitesh S. Chandwani
> University of Texas at Austin
> *
> *   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