Announcement

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

  • logistic regresseion: no observation

    Hello, I am trying to run a logistic regression in stata. I have stata 17. I'm using the 'logit' command and then 4 independent variables (all of them are categorical variables). I also use two 'if-commands', one limiting the age to an age group (the variable is categorized) and one if e(sample). I recoded my dependent variable into a basic dummy variable. However, I keep getting the 'no observation' error. My database i quite large. The dependent variable has over 6800 observations. I tried to check if my if-command is too restrictive, but that does not seem to be the case, because even when leaving out all if-command, stata tells me that there are no observations. Thank you in advance for any advice.

    This is what i type into stata:

    cap drop AfD
    recode s7 1=0 2=0 3=0 4=0 5=0 6=1 7=0 8=. 9=. 10=., gen(AfD)
    logit AfD i.region i.gender i.education i.houseincome if age == 1 & e(sample)

    no observations
    r(2000);

    Last edited by Marit Miguel; 29 Sep 2024, 05:22.

  • #2
    Miguel,
    welcome to this forum.
    It may be that you your -recode- missed the brackets.
    Otherwise, as per FAQ, please post and example/excerpt of your dataset so that interested listers can reply more positively.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      e(sample) is always 0 unless the results of a previous estimation command are still in memory. That could be one reason for the problem.

      Comment


      • #4
        For this particular case, and similar you may face in the future, consider using the following instead of recode.
        Code:
        generate byte AfD = (s7 == 6)
        replace AfD = . if s7 > 7
        You can use conditions to generate binary variables, and for variables with many distinct values typing one by one what you need is painful. Also you can use multiple conditions inside the parentheses with & or |.
        Alfonso Sanchez-Penalver

        Comment

        Working...
        X