Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: looping and replacing values


From   Buzz Burhans <[email protected]>
To   [email protected]
Subject   st: looping and replacing values
Date   Fri, 01 Aug 2003 16:00:20 -0400

I wonder if someone could help me with the syntax below.

I have panel data, long form, which has variables where only one observation contains a value within each panel, and the other observations for that panel and variable are missing

I would like to loop over the panels and the variables and replace the missings for each panel/variable with the single existing observation for that panel that has a value. I used min, but it doesnt really matter if it is min etc, as there is only one value extant for each panel.

There are however, a lot more variables than I show here, and I am quite unsuccesful at making the foreach loops work right.

My attempts look like this, and I would appreciate any help.

Thanks

local Varts "CostCowM7toM12 CostCowQtr CostCWTYrly CostCWTM1toM6 CostCWTM7toM12 CostCWTQtr "
tokenize `Varts'
levels farmid, local(levels)
foreach l of local levels {

syntax [varlist]
foreach var of local Varts{
replace `var' = min(`var')

}
}


Buzz Burhans
[email protected]


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




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