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')