Announcement

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

  • No observations error message when running xtreg

    Hi there,

    I was trying to run an -xtreg- regression on a panel data and got the infamous "no observation" error message. However, if I drop the observations where all variables are missing, the -xtreg- command runs through beautifully and no error message. Please see below the log file.

    Stata is supposed to drop all observations with missing values for any variable used in the regression. So the -
    drop if...- line of code after -preserve- should be irrelevant preceding a regression command. However, Stata seems to suggest I have to manually drop those observations if missing values occur for all variables before it's willing to run -xtreg-.

    Thanks for any pointers.

    Daifeng


    Log file below:

    . use data, clear

    . xtset facid year

    . preserve

    . drop if ladm==. & paydiff_post==. & per_under65==. &per_female==. &per_black==. & per_hispanic==. &per_pov==.
    (19,039 observations deleted)

    .xtreg ladm_mcare paydiff_post per_under65 per_female per_black per_hispanic per_pov i.year, fe

    (runs fine; output omitted)

    . restore

    . xtreg ladm_mcare paydiff_post per_under65 per_female per_black per_hispanic per_pov i.year, fe
    no observations
    r(2000);
    Last edited by Daifeng He; 06 Apr 2022, 00:19.

  • #2
    Your drop command only drops observations for which all values are missing; Stata excludes observations for which any (that is, at least 1) value is missing. Change "&" to "|" and try again.

    Comment


    • #3
      Let me add to what I wrote above that your required if clause can be shortened by using the missing() function.
      Code:
      drop if missing(ladm,paydiff_post,per_under65,per_female,per_black,per_hispanic,per_pov)

      Comment

      Working...
      X