| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: more efficient techniques
Hi Statalist
In the interests of learning some more efficient programming techniques,
I am wondering anyone can suggest a way to improve the following code.
Ideally, I would like to do away with the second -foreach- statement,
which is just a repeat of the first with arguments changed (valm5 for
valm3 and m5b for m4). In this case it was no big deal to just copy the
first statement and amend its contents, but if I had 20 occurences then
I would obviously want to automate the process. I assume a solution
would have to do with using an additional -foreach- statement but not
quite sure how this would work when I have two arguments that need to
change on each loop through.
Thanks in anticipation
gen hsecostw=0 if inlist(m1, 1, 6, 7, 8)
local i=1
foreach x of numlist 1 2 12 52 {
replace hsecostw = valm3/`x' if valm3>=0 & m4==`i'
local ++i
}
local i=1
foreach x of numlist 1 2 12 52 {
replace hsecostw = valm5/`x' if valm5>=0 & m5b==`i'
local ++i
}
--
Michael Alexander
Principal Research Fellow
Australian Institute of Family Studies
300 Queen Street
Melbourne VIC 3000
Tel: 03 9214 7841
Fax: 03 9214 7839
Mob: 0419 406 078
Email: [email protected]
Web-site: www.aifs.gov.au
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/