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

st: Asking Stata to ignore "no observations" when running regressions


From   "Yvonne Capstick" <[email protected]>
To   [email protected]
Subject   st: Asking Stata to ignore "no observations" when running regressions
Date   Thu, 27 Jan 2005 01:07:45 -0500

Using Nick's helpful method for looping (which I initially required to generate proportions), I'm now trying to do looping regressions. What I'd like is the coefficient on regressions for the last 5 years, and to store these just like I was storing the proportions.

My structure is permno year ret rp, where permno is a number which identifies each company uniquely.

I initially try:

gen brp = .
gen bsmb = .
gen bhml = .

forval m = 0/4 {
gen begin = year if mod(year,5) == `m'
bysort permno (year): replace begin = begin[_n-1] if missing(begin)
local i = 1990+`m'
local j = 10107
while `j' < 12000 {
while `i' < 2005 {
reg sret rp if permno == `j' & begin == `i'
replace brp = _b[rp] if year == `i' + 5 & permno == `j' & month == 1 & month[_n-1] == 12
local i = `i' + 5
}
local j = `j' + 1
}
drop begin
}

but, after doing everything successfully for permno 10007, it comes up with no observations for permno 10008. There is indeed no company with permno 10008 - but I would like it to skip to the next permno. Is there an option that asks Stata to skip and increment j once more if there are no observations?

I tried a long-winded way of doing this using an 'if' function, i.e.

forval m = 0/4 {
gen begin = year if mod(year,5) == `m'
bysort permno (year): replace begin = begin[_n-1] if missing(begin)
local i = 1990+`m'
local j = 10107
while `j' < 12000 {
qui gen temp = 1 if permno == `j'
if sum(temp) == 0 {
}
else {
while `i' < 2005 {
reg sret rp if permno == `j' & begin == `i'
replace brp = _b[rp] if year == `i' + 5 & permno == `j' & month == 1 & month[_n-1] == 12
local i = `i' + 5
}
}
local j = `j' + 1
local i = 1990+`m'
drop temp
}
drop begin
}

but this didn't seem to increment either.

Any advice would be much appreciated. In addition, is there an easier way of doing the whole thing without using 'while'? I tried something like:

forval m = 0/4 {
gen begin = year if mod(year,5) == `m'
bysort permno (year): replace begin = begin[_n-1] if missing(begin)
bysort (permno begin): reg sret rp

but this seems to only run one regression.

Thanks very much,
Y

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

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