Announcement

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

  • error help: at level for factor var not present in estimation

    Hi everyone,

    I'm having trouble understanding what an error code means when running the margins command for a logistic regression I have ran.
    The logistic and margins code is:
    Code:
    logistic r_ks4_level2_em_37 i.r_mo_ligmodheavyalc_9 i.r_mo_highestedqual_4  i.r_mo_drugsyn_9 i.r_mo_nosmokedlast2wk_3 i.r_mo_alccon1stmove_3 i.r_mo_prenataldrugyn_3  i.r_mo_familyincomeweek_9 i.r_mo_anxietydr_9 i.r_mo_depressiondr_9 c.r_mz028b i.cr_mo_ethnicgrp_4 i.r_mo_ligmodheavyalc_9#i.r_mo_highestedqual_4
    
    margins r_mo_ligmodheavyalc_9, at(r_mo_highestedqual_4=(1(1)6)) 
    marginsplot, noci ytitle(KS4 outcomes) name(alcoholqual6gcse5ACengmath)
    The error says
    Code:
      at level for factor r_mo_highestedqual_4 not present in estimation
    I've looked at the Stata guide and looked online but I can't seem to make sense of this error. The size of the regression is 5, 700 observations. The alcohol category has 3 category's (no drinking, light drinking, moderate drinking and heavy drinking) and the qualifications variable has 6 categories (no qualifications, CSE, skilled qual, O-level, A-level or equivalent and degree).

    Hope this is enough information,

    Emily

  • #2
    Stata is telling you that in your estimation sample - which includes only observations with no missing values on any of the variables - at least one of the values you specified for r_mo_highestedqual_4 does not appear. Try adding the following before the margins command.
    Code:
    tab r_mo_highestedqual_4 if e(sample)

    Comment


    • #3
      Hi William!

      Thanks for this!

      Emily

      Comment


      • #4
        Some additional advice beyond William's. Since r_mo_highestedqual_4 is a discrete variable in your model, you don't need to use an -at()- option here. The simpler way to get the results you want is just:

        Code:
        margins r_mo_highestedqual_4#r_mo_ligmodheavyalc_9
        Stata will then give you the expected outcome probabilities at all combinations of those two variables that actually exist in the estimation sample.

        Comment


        • #5
          Clyde - this will save time, fantastic. Thank you very much.

          Comment

          Working...
          X