Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: foreach program

From   Scott Cunningham <[email protected]>
To   [email protected]
Subject   Re: st: foreach program
Date   Fri, 8 Sep 2006 11:37:31 -0400

On Sep 8, 2006, at 11:30 AM, Nick Cox wrote:

Also, you are not consistent about what -age-s
you are working with.


You're referring to the last three lines of this original code, right?

foreach i of num 1/`r(max)' {
gen i=perwt if age>=15 & age<=19 & group==`i' & gqtyped==200
gen p=perwt if age>=15 & age<=19 & group==`i'
egen itot=sum(i)
egen ptot=sum(p)
replace ir_level=itot if age==15 & group==`i'
replace pop_level=ptot if age==15 & group==`i'
replace ir=itot/ptot if age==15 & group==`i'
drop i p itot ptot

I only record the "ir," "pop_level," and "ir_level" values for age==15 because I am merging these data with a data set on health outcomes, where health outcomes are delineated by an age variable that is in groupings of five year increments. So, there is a value of "15" for the "age" variable in this separate dataset. I record only values for the age==15 to save space, since I will later be dropping all observations not equal to 15, 20, 25, and so on.

* For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index