Hello
I am trying to run a regression among 220 firms from 1998-2018 to predict a yearly beta value. However, when I try to run the code I first get the error no observations due to not all firms having observations every year due to bankruptcies and so on. Then when I try to suppress this error using capture, which is a function I have never used before, I get the error "last estimates not found". Can someone explain to me where this error arises and possibly suggest an improvement to my current code? My current code looks like this:
// Define global macros
global growth_controls "gini std_zbp_accommodation std_food_entertain std_hosts std_ave_occupancy ln_median_hhincome ln_zillow_homeval ln_county_gdp ln_pop rent_rate employment_rate white_perc college_prop"
// Outer foreach loop for trends
foreach trend in ussearch globalsearch ln_search search_growth house_price house_price_growth ///
log_house_price zhvi zhvi_growth log_zhvi (log_house_price-log_zhvi) mortgage30us mortgage15us {
// Inner foreach loop for variables
foreach var in tot_housing13 owner_housing_units13 renter_housing_units13 tot_vacancy13 ///
tot_forent13 tot_vacation13 tot_forsale13 tot_rented13 tot_sold13 owner_share13 renter_share13 ///
vacant_share13 vacation_share13 real_estate13 realestate_share13 owner_vacent_ratio13 ///
ln_tot_housing13 ln_owner_housing_units13 ln_renter_housing_units13 ln_tot_vacancy13 ///
ln_tot_forent13 ln_tot_vacation13 ln_tot_forsale13 ln_tot_rented13 ln_tot_sold13 ln_owner_share13 ///
ln_renter_share13 ln_vacant_share13 ln_vacation_share13 ln_real_estate13 ln_realestate_share13 ///
ln_owner_vacent_ratio13 {
// Drop iv2 if it already exists
capture drop iv2
// Generate interaction variable
gen iv2 = `var' * `trend'
// First regression and output
qui ivreghdfe npsp_growth_fwd $growth_controls (std_psp_hhi = iv2), ///
absorb(zipcode month2 county#month2) cluster(zipcode)
outreg2 using "E:\Code_RPT\t_`trend'_`var'.doc", replace ///
sdec(3) bdec(3) rdec(3)
// Second foreach loop for dependent variables
foreach dv in psp_growth_fwd npsp_growth_fwd psp_price_fwd npsp_price_fwd {
qui ivreghdfe `dv' $growth_controls (std_psp_hhi = iv2), ///
absorb(zipcode month2 county#month2) cluster(zipcode)
outreg2 using "E:\Code_RPT\t_`trend'_`var'.doc", append ///
sdec(3) bdec(3) rdec(3)
}
// Drop the interaction variable
drop iv2
}
}
I am trying to run a regression among 220 firms from 1998-2018 to predict a yearly beta value. However, when I try to run the code I first get the error no observations due to not all firms having observations every year due to bankruptcies and so on. Then when I try to suppress this error using capture, which is a function I have never used before, I get the error "last estimates not found". Can someone explain to me where this error arises and possibly suggest an improvement to my current code? My current code looks like this:
// Define global macros
global growth_controls "gini std_zbp_accommodation std_food_entertain std_hosts std_ave_occupancy ln_median_hhincome ln_zillow_homeval ln_county_gdp ln_pop rent_rate employment_rate white_perc college_prop"
// Outer foreach loop for trends
foreach trend in ussearch globalsearch ln_search search_growth house_price house_price_growth ///
log_house_price zhvi zhvi_growth log_zhvi (log_house_price-log_zhvi) mortgage30us mortgage15us {
// Inner foreach loop for variables
foreach var in tot_housing13 owner_housing_units13 renter_housing_units13 tot_vacancy13 ///
tot_forent13 tot_vacation13 tot_forsale13 tot_rented13 tot_sold13 owner_share13 renter_share13 ///
vacant_share13 vacation_share13 real_estate13 realestate_share13 owner_vacent_ratio13 ///
ln_tot_housing13 ln_owner_housing_units13 ln_renter_housing_units13 ln_tot_vacancy13 ///
ln_tot_forent13 ln_tot_vacation13 ln_tot_forsale13 ln_tot_rented13 ln_tot_sold13 ln_owner_share13 ///
ln_renter_share13 ln_vacant_share13 ln_vacation_share13 ln_real_estate13 ln_realestate_share13 ///
ln_owner_vacent_ratio13 {
// Drop iv2 if it already exists
capture drop iv2
// Generate interaction variable
gen iv2 = `var' * `trend'
// First regression and output
qui ivreghdfe npsp_growth_fwd $growth_controls (std_psp_hhi = iv2), ///
absorb(zipcode month2 county#month2) cluster(zipcode)
outreg2 using "E:\Code_RPT\t_`trend'_`var'.doc", replace ///
sdec(3) bdec(3) rdec(3)
// Second foreach loop for dependent variables
foreach dv in psp_growth_fwd npsp_growth_fwd psp_price_fwd npsp_price_fwd {
qui ivreghdfe `dv' $growth_controls (std_psp_hhi = iv2), ///
absorb(zipcode month2 county#month2) cluster(zipcode)
outreg2 using "E:\Code_RPT\t_`trend'_`var'.doc", append ///
sdec(3) bdec(3) rdec(3)
}
// Drop the interaction variable
drop iv2
}
}
Comment