Hello, I'm looping over a regression so that in each loop 1 observation is dropped, for example in the first loop only observation 1 is dropped, loop 2 only observation 2 is dropped and observation 1 is back. so far this is the code im working with (im trying to store the coefficients of one of the variables in each loop)
sysuse auto,clear
gen coef = _n
forvalues i = 1/74{
drop if _n=`i'
reg price mpg trunk
replace coef = _b[mpg] if _n==`i'
}
the problem with the drop command is it ommits the observations but does not return them back in the second loop so the number of observations keeps dropping rather than always being n-1 in each regression. What is the code used to only ommit it for the regression in the loop.
sysuse auto,clear
gen coef = _n
forvalues i = 1/74{
drop if _n=`i'
reg price mpg trunk
replace coef = _b[mpg] if _n==`i'
}
the problem with the drop command is it ommits the observations but does not return them back in the second loop so the number of observations keeps dropping rather than always being n-1 in each regression. What is the code used to only ommit it for the regression in the loop.
Comment