keep if quantity!=. & price !=.
qui sum hscode_i_link
global N = r(max)
cap dropvars q_hat e
gen q_hat = .
forvalues i = 1/$N{
qui reg quantity price if (hscode_i_link==`i')
qui predict e if e(sample), res
qui replace q_hat = e if e(sample)
drop e
}
这样总是出现“insufficient observations r(2001);”
r(2001):
[P] error . . . . . . . . . . . . . . . . . . . . . . . . Return code 2001
insufficient observations;
You have requested some statistical calculation, and while there
are some observations, the number is not sufficient to carry out
your request.
即使看懂这个字面意思,还是完全不知道哪里出错了,请各位指点迷津啊!
回归的时候是按hscode_i_link分类回归的。因为加了 cap noisily
forvalues i = 1/$N{
qui capture noisily reg quantity price if (hscode_i_link==`i')
qui predict e if e(sample)
qui replace q_hat = e if e(sample)
drop e
}