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


From   Hitesh Chandwani <[email protected]>
To   [email protected]
Subject   Re: st: Arrays and loops for Stata
Date   Fri, 13 Apr 2012 11:21:18 -0500

Phil,

I think -egen- rowlast and rowfirst serve my purpose..but thanks for the input.

Stas,

Your suggestion works really well....thanks so much!
What would the change in your code be if I needed to generate the
first date (firstd) variable?

Regards,
Hitesh

On Fri, Apr 13, 2012 at 9:57 AM, Phil Clayton
<[email protected]> wrote:
> 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/



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


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