Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error last estimates not found.

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

  • #2
    Before talking about the possible causes of this error, I want to comment on
    Then when I try to suppress this error using capture,...
    -capture- does not suppress errors. It suppresses error messages and it allows execution to continue despite the existence of the error condition. As such, it should only be used when the error condition is expected, and either it does not interfere with later computation, or you can write code that handles the error either by correcting it or by bypassing the parts of the later calculations that would be thrown off by the error. In short, if not used very carefully, -capture- simply postpones the "day of reckoning," which often just means that you find about your errors when it is too late!

    Error messages are your friend. You should welcome them. Error early and error often! They let you know that there is a problem that renders your calculations of dubious or no value. The response should never be to suppress the error message. It should be to find the source of the error and fix it.

    With all of that said, the "no observations" error in regression commands occurs commonly. There are three common situations that give rise to it. Two of them are related to the fact that any observation that contains a missing value for any variable mentioned in the regression command will be omitted from the estimation sample. So the two common ways this happens are:
    1. There is some variable that has all missing values. This results in every observation in the data set being omitted, hence "no observations" for the regression. It should be easy enough to find such a variable just by running the -summarize- command with each of the variables. If there are no observations, Stata will tell you that it has 0 observations. The solution is to either omit the variable from the model, or, fix the data set so that the variable actually contains information.
    2. Much harder to spot and deal with is when every observation in the data set has a missing value on one (or more) of the variables, but it isn't the same offending variable in every observation. This typically happens in observational data where missingness occurs haphazardly. If the overall rate of missingness is high enough, it can turn out that every single observation has a missing value for some variable. Then you get the "no observations" error. This problem is harder to fix, and may require both getting data for the missing values, and perhaps leaving some variable(s) out of the model. Imputing the missing values may be a possibility, too.
    The third way that "no observations" commonly pops up is when one (or more) of the variables in the model is a string variable. String variables can't be used in numeric computations, and for the purposes of regression calculations, they are just like a variable whose values are all missing. You can find the offending variable(s) by running -describe- on all of the model variables. Look in column of the -describe- output headed Storage type. If a variable's storage type begins with the letters str, it is a string variable. Once you have found it, you either have to omit it from the model, or, more typically, convert it to a numeric storage type. This is doable with commands such as -encode- or -destring- or -egen, group()-, or with a Stata date function. Make sure you understand which of these commands is appropriate to the particular variable: they do different things, and if you choose the wrong one you can end up with results that look correct but are completely wrong and will cause your regression results to be bizarre and meaningless. So if you are not familiar with these functions, be sure to read their -help- files before using them. I'll also point out that there are many posts here on Statalist relating to the differences between these and what goes wrong if you pick the wrong one.

    Comment

    Working...
    X