Announcement

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

  • Error: only one level in treatment variable

    Dear statelister,

    I run into a problem while running the following code:
    teffects nnmatch (_mbdty_diarrhea_new c_age m_age_atbirth m_married m_ed_yr_cat c_sex m_place_delivery_cat) (bf_dummy6), nneighbor(3) biasadj(c_age m_age_atbirth) ematch(m_married m_ed_yr_cat c_sex m_place_delivery_cat)

    the error message is:there is only one level in treatment variable bf_dummy6; this is not allowed
    r(459);

    however the variable bf_dummy6 is a dummy variable like following:
    bf_dummy6 | Freq. Percent Cum.
    ------------+-----------------------------------
    0 | 217,465 18.13 18.13
    1 | 981,928 81.87 100.00
    ------------+-----------------------------------
    Total | 1,199,393 100.00

    can anyone help and tell me what is wrong in the code? Thanks in advance

    Best
    Yoyo

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(bf_dummy6 mbdty_diarrhea_new) long c_age byte c_sex float(m_age_atbirth m_ed_yr_cat)
    1 0 3 1 17 0
    1 0 4 1 21 0
    1 0 1 1 25 0
    1 0 1 2 25 0
    0 0 0 2 35 0
    1 1 1 2 33 0
    1 0 0 2 22 0
    0 0 0 1 18 .
    1 1 1 2 26 0
    1 0 3 2 19 0
    1 1 1 2 37 0
    1 0 4 1 41 0
    1 1 1 2 20 0
    1 0 2 1 32 .
    1 0 0 2 29 0
    1 0 3 2 35 0
    1 0 1 1 35 .
    1 1 1 1 42 0
    1 0 1 1 25 0
    1 0 4 2 19 0
    1 0 3 2 17 0
    1 0 3 1 27 0
    0 1 0 2 29 0
    1 0 3 2 25 0
    0 1 0 1 32 0
    1 0 0 1 29 0
    1 1 2 2 33 .
    0 1 0 1 22 0
    1 1 3 1 22 0
    1 0 3 2 33 0
    1 0 3 2 30 0
    0 0 0 1 23 0
    1 1 3 1 21 0
    1 0 1 2 32 0
    1 0 2 2 24 0
    1 0 4 1 23 0
    1 0 0 2 25 0
    1 0 2 1 18 0
    1 1 3 2 22 0
    1 1 2 2 27 0
    1 1 0 2 25 .
    1 0 1 1 30 0
    1 0 3 2 22 0
    1 0 3 1 25 0
    1 1 1 1 22 0
    1 1 2 1 16 0
    1 0 1 2 31 0
    1 0 3 2 39 0
    1 0 2 2 21 0
    1 1 2 2 25 0
    1 0 2 1 35 0
    1 0 1 1 28 0
    1 0 2 2 38 0
    1 0 1 1 34 0
    1 0 3 1 33 0
    1 0 2 1 20 0
    1 0 2 1 29 0
    0 0 0 1 27 0
    1 1 1 1 29 0
    0 0 0 2 22 0
    1 1 1 2 19 .
    1 1 1 2 32 0
    0 0 0 2 20 .
    1 0 3 2 26 0
    1 0 1 2 21 .
    1 0 0 1 25 0
    1 0 1 2 36 0
    0 0 0 1 24 0
    1 0 1 2 30 0
    1 0 2 2 28 0
    1 0 1 2 22 0
    1 0 4 2 26 0
    0 0 0 1 26 0
    1 0 0 2 35 0
    1 0 3 1 29 0
    1 0 1 1 30 0
    1 1 0 1 34 0
    1 0 2 1 19 0
    1 1 1 1 18 0
    1 0 1 2 42 0
    0 0 0 2 30 0
    1 0 4 2 23 0
    1 0 0 1 36 0
    1 0 1 2 22 .
    1 1 0 2 18 0
    1 0 2 2 20 0
    1 0 3 2 33 0
    1 0 1 2 25 0
    1 0 1 1 24 0
    1 1 1 1 18 0
    1 0 4 1 18 0
    0 0 0 1 25 0
    1 0 3 2 31 0
    0 0 0 1 27 0
    0 1 0 1 30 0
    1 0 3 1 40 0
    1 0 3 1 36 0
    1 0 4 2 26 0
    1 1 0 1 22 0
    1 0 1 2 27 0
    end
    label values mbdty_diarrhea_new mbdty_diarrhea_new
    label def mbdty_diarrhea_new 0 "No", modify
    label def mbdty_diarrhea_new 1 "Yes", modify
    label values c_sex c_sex
    label def c_sex 1 "Male", modify
    label def c_sex 2 "Female", modify
    label values m_ed_yr_cat m_ed_yr_cat
    label def m_ed_yr_cat 0 "No to Primary education", modify



  • #2
    I don't see anything wrong with the code. The problem is probably with your data.

    -teffects-, like all estimation commands, excludes from the estimation sample any observation where any of the variables in the command is missing. In your example data the variable m_ed_yr_cat has some missing values. So all of those observations will be excluded from the -teffects- estimation. There are other variables mentioned in your -teffects- command that do not appear in your example, but my guess is that there are some missing values for some of those as well. I think what is happening is that after you omit all the observations that have any missing values on the mentioned variables, the remaining observations all have the same value of bf_dummy6. You can test that easily enough:

    Code:
    egen mcount = rowmiss((_mbdty_diarrhea_new c_age m_age_atbirth m_married m_ed_yr_cat c_sex m_place_delivery_cat bf_dummy6)
    tab bf_dummy6 is mcount == 0

    Comment


    • #3
      Hi Clyde(I was hoping that you would help), thanks for your answer and you are totally right about this. I got only bf_dummy6=0 left in the observations. Best Yoyo

      Comment

      Working...
      X