Announcement

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

  • Problem with the user generated command qregsel

    I am trying to use the user-generated command qregsel, but I am encountering two separate issues. The first issue is the error message: "Dependent variable never censored because of selection or selection indicator is not binary," even though the selection variable is binary. The second issue is: "Factor-variable and time-series operators not allowed." I need help using indicator variables in the list of control variables.



    qregsel log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(log_avrg_cost inc_d endentulism race age_cat) byte(male education veteran) float mothered byte wealth float(smoke_now chronicdisease) byte r11dentst
     5.860786 0 0 1 3 0 5 0 1 4 0 3 1
            0 0 0 1 1 0 5 0 1 4 0 3 1
     6.478509 0 0 1 2 0 3 0 0 4 0 0 1
     7.824446 0 0 1 2 0 4 0 1 4 1 0 1
     6.398595 0 0 1 3 1 5 1 1 4 0 2 1
     8.699764 0 0 1 2 0 5 0 0 4 0 0 1
     5.525453 0 0 4 3 0 5 0 1 4 0 2 1
            0 0 0 3 3 0 1 0 . 2 0 2 0
     6.685861 0 0 3 3 0 1 0 0 1 0 2 1
     6.398595 0 0 1 2 0 1 0 1 4 0 1 1
     7.378384 0 0 1 4 1 5 1 0 4 0 2 1
            0 0 0 3 3 0 1 0 0 1 0 2 1
            0 0 1 4 3 1 1 0 0 1 0 3 0
            0 0 1 2 3 0 3 0 0 1 0 1 1
            0 0 0 2 3 1 1 0 . 1 0 0 0
     7.151485 0 0 1 3 0 4 0 1 1 0 1 1
            0 1 1 2 3 0 1 0 . 1 0 1 0
     6.216606 0 0 1 3 0 4 0 1 4 0 0 1
     5.993961 0 0 1 3 1 5 1 1 4 0 0 1
      8.03948 0 0 1 3 0 1 0 1 4 0 1 1
            0 0 0 1 3 0 3 0 1 1 0 2 0
     5.303305 0 1 4 3 0 5 0 0 4 0 2 1
     5.303305 0 0 4 3 1 5 1 0 4 0 3 0
     4.620059 0 0 1 3 0 3 0 0 1 0 0 1
            0 0 1 1 3 1 4 1 . 2 0 1 0
     7.313887 0 0 1 2 0 5 0 1 2 0 0 1
     8.881975 0 0 1 4 0 5 0 1 4 0 2 1
     5.993961 0 0 1 3 1 5 1 1 4 0 2 1
     7.824446 0 0 1 3 0 3 0 1 4 0 0 1
     7.523481 0 0 1 3 1 5 0 0 4 0 3 1
     6.803505 0 0 1 3 0 5 0 1 4 0 1 1
            0 0 0 2 3 0 1 0 0 3 0 2 1
            0 0 0 2 3 0 5 0 1 1 0 2 0
            0 0 1 2 3 0 1 0 0 4 0 1 0
            0 0 1 2 2 0 3 0 0 1 0 0 0
     6.398595 0 0 2 3 1 3 1 1 3 0 3 1
            0 0 0 2 3 0 3 0 1 3 0 0 1
     6.908755 0 0 2 3 1 3 0 0 2 . 2 0
     5.786897 0 0 3 1 0 3 0 1 4 0 0 1
     4.836282 0 0 4 3 0 1 0 0 4 0 0 1
     5.303305 0 0 4 4 1 5 0 0 4 0 0 1
     6.908755 0 0 3 3 1 4 1 1 4 0 1 1
     3.314186 0 0 1 2 0 4 0 1 4 0 0 1
      7.31422 0 0 1 2 0 4 0 0 4 0 1 1
     8.987322 0 0 2 3 0 5 0 0 1 0 4 1
            0 0 1 4 3 0 4 0 0 2 0 0 0
     4.912655 1 0 1 3 1 1 0 1 2 0 1 1
      5.86221 0 0 1 3 0 5 0 1 2 0 1 1
     5.239098 0 0 1 3 1 3 1 0 4 0 2 1
            0 0 0 2 3 0 4 0 0 3 0 3 0
     6.803505 0 0 1 4 1 5 1 1 4 0 2 1
     7.438972 0 0 3 3 0 3 0 0 3 0 1 1
            0 0 1 3 3 1 2 1 0 3 0 1 0
    4.6151204 0 0 4 4 1 5 0 0 2 0 1 0
    3.9318256 0 0 4 3 0 5 0 0 2 0 2 1
            0 0 0 2 3 0 1 0 0 1 1 2 0
     5.351858 0 0 2 3 0 3 0 0 1 0 1 1
            0 0 0 2 3 0 1 0 . 1 0 2 0
      6.53814 0 0 1 3 1 4 1 0 1 0 3 1
     7.313887 1 0 4 2 0 1 0 1 2 0 6 1
     8.101981 0 0 1 4 1 3 1 1 4 0 4 1
      6.29803 0 0 1 3 0 1 0 1 4 0 1 1
     6.055613 0 0 1 3 0 5 0 1 3 0 1 1
            0 0 0 1 3 0 3 0 1 2 0 2 0
      7.91972 0 0 1 4 0 4 0 0 4 0 3 1
     6.908755 0 0 1 4 1 5 1 . 4 0 1 1
     7.003974 0 0 1 4 1 4 1 1 4 0 1 1
     6.763885 0 0 1 3 0 3 0 0 4 0 4 1
            0 0 0 1 2 0 3 0 1 2 0 1 1
            0 0 0 1 3 0 2 0 0 3 0 0 1
    1.7917595 0 0 3 3 0 3 0 . 1 0 3 1
            0 1 0 2 1 0 1 0 0 1 1 1 0
            0 0 0 2 1 0 4 0 0 1 1 2 0
            0 0 1 2 3 0 4 0 1 2 0 3 0
            0 0 0 1 3 0 1 0 0 1 0 2 0
     6.685861 0 0 1 3 1 4 1 1 2 0 1 1
     5.463832 0 0 1 3 1 3 0 . 3 0 2 1
            0 0 0 1 3 0 3 0 1 4 0 1 0
     4.620059 0 0 1 4 1 1 1 0 3 0 0 1
     6.634634 0 0 1 3 1 5 1 1 4 0 2 1
     5.525453 0 0 1 3 1 5 0 0 4 0 2 0
     5.860786 0 0 1 1 0 5 0 1 4 0 0 1
            0 0 1 1 3 1 2 0 0 3 0 3 0
     6.246107 0 0 3 2 0 1 0 0 3 . 2 1
            0 0 0 1 4 1 1 0 0 2 0 3 0
     5.673323 0 0 1 4 0 4 0 0 3 0 0 1
            0 0 1 2 3 0 3 0 0 1 0 3 0
            0 0 0 2 3 1 2 0 1 1 1 0 0
            0 1 1 2 3 1 3 0 1 2 1 0 0
            0 0 0 2 3 0 4 0 0 2 0 2 0
     3.433987 0 0 2 3 1 4 1 0 3 0 2 1
    3.9318256 1 0 2 1 0 4 0 0 3 1 2 1
     5.170484 0 0 2 3 1 1 0 1 2 0 3 1
            0 0 0 2 2 1 3 1 0 1 . 4 1
            0 0 1 1 3 1 1 1 0 3 0 4 0
     7.601402 0 0 1 3 0 1 0 0 4 0 0 1
            0 0 1 2 3 1 1 1 . 2 0 3 0
            0 0 0 2 2 0 3 0 1 3 0 1 0
            0 0 1 1 2 0 3 0 . 2 1 2 0
            0 1 1 1 3 1 4 0 1 4 0 4 0
    end
    label values inc_d inc_d
    label def inc_d 0 "No", modify
    label def inc_d 1 "Yes", modify
    label values endentulism endentulism
    label def endentulism 0 "No", modify
    label def endentulism 1 "Yes", modify
    label values race race
    label def race 1 "White", modify
    label def race 2 "Black", modify
    label def race 3 "Hispanic", modify
    label def race 4 "Other", modify
    label values age_cat age_cat
    label def age_cat 1 "50-59", modify
    label def age_cat 2 "60-69", modify
    label def age_cat 3 "70-79", modify
    label def age_cat 4 "80+", modify
    label values male male
    label def male 0 "Female", modify
    label def male 1 "Male", modify
    label values education EDUC
    label def EDUC 1 "1.lt high-school", modify
    label def EDUC 2 "2.ged", modify
    label def EDUC 3 "3.high-school graduate", modify
    label def EDUC 4 "4.some college", modify
    label def EDUC 5 "5.college and above", modify
    label values veteran veteran
    label def veteran 0 "No", modify
    label def veteran 1 "Yes", modify
    label values mothered mothered
    label def mothered 0 "Less than High School", modify
    label def mothered 1 "High School or Higher", modify
    label values smoke_now smoke_now
    label def smoke_now 0 "Non-Smoker", modify
    label def smoke_now 1 "Currently Smokes", modify
    label values r11dentst YESNO
    label def YESNO 0 "0.no", modify
    label def YESNO 1 "1.yes", modify

  • #2
    Can you run the following code successfully:
    Code:
    webuse womenwk, clear
    qregsel wage educ age, select(married children educ age) quantile(.1 .5 .9)
    And qregsel need function mm_cond, you can install it using
    Code:
    ssc install moremata, replace

    Comment


    • #3
      When I run qregsel with the womenwk dataset I get an output, but when I try using the function on my data set, I get still get the error Dependent variable never censored because of selection or selection indicator is not binary.
      r(198); I updated the moremata package and I still get the error above.


      qregsel log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)

      Comment


      • #4
        Try to detach value number from variables.

        Code:
        label values education EDUC
        label def EDUC 1 "lt high-school", modify
        label def EDUC 2 "ged", modify
        label def EDUC 3 "high-school graduate", modify
        label def EDUC 4 "some college", modify
        label def EDUC 5 "college and above", modify
        
        label values r11dentst YESNO
        label def YESNO 0 "no", modify
        label def YESNO 1 "yes", modify
        https://www.statalist.org/forums/for...implementation

        Comment


        • #5
          Code:
           
          label val log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease r11dentst
          
           qregsel log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)
          
          Dependent variable never censored because of selection or selection indicator is not binary.

          My apologies, i don't know why this post copied so many times, I tried dropping the value labels and I still get the error "Dependent variable never censored because of selection or selection indicator is not binary."
          Last edited by Luis Mijares Castaneda; 03 Feb 2025, 19:46.

          Comment


          • #6
            Code:
             
            label val log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease r11dentst
            
             qregsel log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)
            
            Dependent variable never censored because of selection or selection indicator is not binary.


            Comment


            • #7
              Sorry for #2 and #4. The basic grammar of -qregsel- is qregsel depvar varlist [if] [in] , select([depvar_s =] varlist_s) quantile(#)
              Like heckman model, if depvar_s is specified, it should be coded as 0 or 1, with 0 indicating an observation not selected and 1 indicating a selected observation. If depvar_s is not specified, observations for which depvar is not missing are assumed selected, and those for which depvar is missing are assumed not selected.

              And that is obvious when set trace on:

              Code:
              - tokenize `select', parse("=")
              = tokenize r11dentst=race age_cat, parse("=")
              - if "`2'" != "=" {
              = if "=" != "=" {
                local x_s `select'
                tempvar y_s
                qui gen byte `y_s' = (`depvar'!=.) `if' `in'
                }
              - else {
              - local y_s `1'
              = local y_s r11dentst
              - local x_s `3'
              = local x_s race age_cat
              - }
              - capture unab x_s : `x_s'
              = capture unab x_s : race age_cat
              
              ..........
              
              - qui tab `y_s'
              = qui tab r11dentst
              - if r(r) != 2 {
                dis as error "Dependent variable never censored because of selection or selection indicator is not binary."
                exit 198
                }
              So I think the solution is replacing your dependent variable to missing if its value is 0.

              Code:
              replace log_avrg_cost=. if log_avrg_cost==0
              qregsel log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)
              
              Grid for the copula parameter (100)
              ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
              ..................................................
              ..................................................
               
              Quantile selection model                         Number of obs      =       87
                                                               Selected           =       56
                                                               Nonselected        =       31
              Copula parameter (gaussian):    -0.28
              --------------------------------------------------------------------------------
               log_avrg_cost |      Coef.
              ---------------+----------------------------------------------------------------
              q10            |
                       inc_d |  -.5917213
                 endentulism |     1.0741
                        race |  -.1868762
                     age_cat |   .9016545
                        male |  -.2918677
                   education |   .0164915
                     veteran |   -.711922
                    mothered |   1.296248
                      wealth |     .14869
                   smoke_now |   1.889079
              chronicdisease |  -.0735079
                       _cons |   1.741545
              ---------------+----------------------------------------------------------------
              q25            |
                       inc_d |  -.1185757
                 endentulism |   .3394867
                        race |  -.4275782
                     age_cat |    .190285
                        male |     -.7211
                   education |   .0247499
                     veteran |  -.0931269
                    mothered |   .5616347
                      wealth |   .3367208
                   smoke_now |  -1.026533
              chronicdisease |   .2834159
                       _cons |   4.065812
              ---------------+----------------------------------------------------------------
              q50            |
                       inc_d |  -.7411483
                 endentulism |   -.307586
                        race |  -.3676573
                     age_cat |     .34587
                        male |   -1.18841
                   education |     .01476
                     veteran |    .629845
                    mothered |   .3406209
                      wealth |  -.0488742
                   smoke_now |  -1.015606
              chronicdisease |   .2509791
                       _cons |   5.663649
              ---------------+----------------------------------------------------------------
              q75            |
                       inc_d |   -.477296
                 endentulism |   3.650261
                        race |  -.3350918
                     age_cat |    .502547
                        male |  -1.797146
                   education |   .0621423
                     veteran |   .3633428
                    mothered |   .1116142
                      wealth |   .2105526
                   smoke_now |   .7805313
              chronicdisease |   .3878358
                       _cons |   5.169081
              ---------------+----------------------------------------------------------------
              q90            |
                       inc_d |  -.9127351
                 endentulism |  -1.409566
                        race |   -.310367
                     age_cat |  -.0760186
                        male |  -1.806011
                   education |   .1288075
                     veteran |   .4739201
                    mothered |   .0328543
                      wealth |   .2035147
                   smoke_now |  -.2715086
              chronicdisease |   .4045722
                       _cons |    7.19649
              --------------------------------------------------------------------------------

              Comment


              • #8
                Thank you this worked, however, I was wondering if you knew how to introduce factor variables to the qregsel model? I want to see the coefficient on each level of the categorical variables

                Code:
                
                . qregsel log_avrg_cost i.inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)
                factor-variable and time-series operators not allowed
                r(101);

                Comment


                • #9
                  Yes, use xi: before qregsel.

                  Code:
                  xi: qregsel log_avrg_cost i.inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11dentst) quantile(0.10 0.25 0.5 0.75 0.90)

                  Comment


                  • #10
                    Sorry, but two follow-up questions, I tried implementing the xi: prefix and I don't get coefficients for the levels of the variables, also I was wondering if it was possible to implement survey weights? I know the heckman model states that "Weights are not allowed with the bootstrap prefix twostep, vce(), first, lrmodel, and weights are not allowed with the svy prefix pweights, fweights, and iweights are allowed with maximum likelihood estimation; see weight. No weights are allowed if twostep is specified." But I was wondering if you knew of a possible work around?


                    Code:
                    . xi: qregsel log_avrg_cost inc_d endentulism race age_cat male education veteran mothered wealth smoke_now chronicdisease, select(r11d
                    > entst) quantile(0.10 0.25 0.5 0.75 0.90)
                    Grid for the copula parameter (100)
                    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
                    ..................................................
                    ..................................................
                     
                    Quantile selection model                         Number of obs      =    12364
                                                                     Selected           =     8156
                                                                     Nonselected        =     4208
                    Copula parameter (gaussian):     0.32
                    --------------------------------------------------------------------------------
                     log_avrg_cost | Coefficient
                    ---------------+----------------------------------------------------------------
                    q10            |
                             inc_d |   .0221442
                       endentulism |   .0514224
                              race |  -.0769367
                           age_cat |   .1770904
                              male |  -.0648551
                         education |   .0225106
                           veteran |   .0289118
                          mothered |  -.0756595
                            wealth |   .1519029
                         smoke_now |   .0843225
                    chronicdisease |   .0252361
                             _cons |   3.650929
                    ---------------+----------------------------------------------------------------
                    q25            |
                             inc_d |  -.0101356
                       endentulism |   .0881108
                              race |  -.0570073
                           age_cat |   .1234644
                              male |  -.0749183
                         education |   .0444297
                           veteran |   .0568609
                          mothered |   -.046574
                            wealth |   .1554628
                         smoke_now |   .1718711
                    chronicdisease |   .0180574
                             _cons |   4.491532
                    ---------------+----------------------------------------------------------------
                    q50            |
                             inc_d |  -.0188251
                       endentulism |   .3251516
                              race |  -.0109526
                           age_cat |   .0870298
                              male |  -.0658264
                         education |   .0444925
                           veteran |   .0432081
                          mothered |   .0175573
                            wealth |   .1209759
                         smoke_now |   .1178917
                    chronicdisease |   .0097562
                             _cons |   5.444097
                    ---------------+----------------------------------------------------------------
                    q75            |
                             inc_d |  -.0707277
                       endentulism |   .2264196
                              race |   .0322966
                           age_cat |      .0885
                              male |  -.0558291
                         education |    .036868
                           veteran |   .0564231
                          mothered |   .0546447
                            wealth |   .0987129
                         smoke_now |   .0158849
                    chronicdisease |   .0102929
                             _cons |   6.339289
                    ---------------+----------------------------------------------------------------
                    q90            |
                             inc_d |  -.0221718
                       endentulism |   .2190943
                              race |  -.0105137
                           age_cat |   .0728167
                              male |  -.0603088
                         education |   .0420561
                           veteran |   .1064943
                          mothered |    .016353
                            wealth |    .107214
                         smoke_now |   .1300904
                    chronicdisease |  -.0007818
                             _cons |   7.125686
                    --------------------------------------------------------------------------------
                    
                    . 
                    end of do-file

                    Comment


                    • #11
                      First, you must add an i. prefix before category variables. As you can see in #9, I add i. before inc_d, it's i.inc_d now.
                      Second, I don't find weight option in grammar of qregsel command, so it seems that it does not support weight. You can try to use -arhomme- command as an alternative.

                      Comment

                      Working...
                      X