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 at the end of May, and its replacement, statalist.org is already up and running.


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

st: programming loops efficiently


From   "Breeze, Elizabeth" <e.breeze@ucl.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: programming loops efficiently
Date   Wed, 14 Nov 2012 09:53:05 +0000

I am creating some variables and I am sure that my syntax is needlessly long where there is a repeat pattern to the commands.

I have variables  Vh01-Vh25 which give the number of hours worked by persons number 01-25 respectively.
I want to find which person worked maximum hours and what that maximum was
egen maxhr = rowmax(Vh01-Vh25)  gives me the maximum number of hours 

Is there a quick way to find the person number with the max no. hours by taking advantage of those last two digits of Vh01-Vh25? 
 I can do it with many lines of syntax but am sure there must be a neater way using some form of loop. 
Each record in the dataset concerns one interviewee and persons 01-25 are people who work for the interviewee

A further complication is that more than one person may work that maximum number of hours.

Also is there an equivalent to rowmax that gives the second to largest value in the series?

Grateful for any tips.    I am not a programmer

Elizabeth Breeze


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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