Announcement

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

  • qregsel implementation

    Dear members
    Am implementing the recommendations in this paper https://www.stata.com/meeting/us20/s..._Siravegna.pdf
    My selection variable is sex ie select(sex) coded 0, 1.
    However, when I run the model as follows:
    Code:
    qregsel yield age educ , select( sex ) quantile(.1 .5 .9) grid_min(-.9) grid_max(.9) grid_length(0.05)
    This error keeps recurring

    __000001 should be binary.
    r(198);
    What I doing wrong please
    Last edited by Co Ar; 26 Sep 2020, 06:23. Reason: Am experiencing problems posting please

  • #2
    It would help if you reassure us and yourself that "sex" really is binary. Show us the results of
    Code:
    tabulate sex
    tabulate sex, missing
    Do you get the same error if you omit the space before and the space after 'sex' in the select() option?

    What if you run the command adding an -if- qualifier of form -if inlist(sex,0,1)-?

    With a log-file open, -set trace on- and run your command. -set trace off- at the end. Look at the log-file. Does the detailed output around the error provide more clues about the problem?

    Comment


    • #3
      I have re-run the diagnostics:
      for the
      Code:
       
       tabulate sex
      I get:
      sex Freq. Percent Cum.
      0 131 15.07 15.07
      1 738 84.93 100.00
      Total 869 100.00
      For next
      Code:
      tabulate sex, missing
      I get
      sex Freq. Percent Cum.
      0 131 15.07 15.07
      1 738 84.93 100.00
      Total 869 100.00
      For trace:
      I get
      HTML Code:
      - 
      - syntax varlist(numeric) [if] [in], SELect(string) quantile(string) grid_min(real) grid_max(real) grid_length(real) [ copula(string) noCONStant plot ]
      - gettoken depvar indepvars : varlist
      - _fv_check_depvar `depvar'
      = _fv_check_depvar yield
      - fvexpand `indepvars'
      = fvexpand  age educ
      - local cnames `r(varlist)'
      = local cnames age educ
      - tokenize `select', parse("=")
      = tokenize sex, parse("=")
      - if "`2'" != "=" {
      = if "" != "=" {
      - local x_s `select'
      = local x_s sex
      - tempvar y_s
      - qui gen `y_s' = (`depvar'!=.)
      = qui gen __000001 = (yield!=.)
      - }
      - else {
        local y_s `1'
        local x_s `3'
        }
      - capture unab x_s : `x_s'
      = capture unab x_s : sex
        --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- begin unab ---
        - version 6
        - gettoken user 0: 0, parse(" :")
        - gettoken colon 0: 0, parse(" :")
        - if `"`colon'"' != ":" { error 198 }
        = if `":"' != ":" { error 198 }
        - syntax [varlist(default=empty)] [, MIN(integer 1) MAX(integer 120000) NAME(string)]
        - c_local `user' `varlist'
        = c_local x_s sex
        - local n : word count `varlist'
        = local n : word count sex
        - if `n'>=`min' & `n'<=`max' { exit }
        = if 1>=1 & 1<=120000 { exit }
        ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- end unab ---
      - marksample touse
      - markout `touse' `y_s' `x_s'
      = markout __000002 __000001 sex
      - tempvar touse1
      - mark `touse1' if `y_s'==1
      = mark __000003 if __000001==1
      - markout `touse1' `depvar' `indepvars'
      = markout __000003 yield  age educ
      - qui replace `touse' = 0 if `touse1'==0 & `y_s'==1
      = qui replace __000002 = 0 if __000003==0 & __000001==1
      - qui tab `y_s'
      = qui tab __000001
      - if r(r) != 2 {
      - dis as error "`y_s' should be binary."
      = dis as error "__000001 should be binary."
      __000001 should be binary.
      - exit 198
        }

      Comment


      • #4
        Below is part of the data

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float yield byte(sex age educ)
             1000 1 28 2
              240 0 60 2
              250 0 40 4
              125 1 41 2
              125 1 54 2
                4 1 72 2
         666.6667 1 35 2
         352.9412 1 53 2
              225 0 48 2
              200 1 56 2
              200 1 42 2
        293.33334 1 59 2
               96 1 81 2
               10 0 41 2
               10 1 39 2
              160 1 45 2
              600 1 33 2
               65 1 47 2
               72 0 60 1
              255 0 44 2
               50 1 38 2
               42 0 49 2
              120 1 38 2
               30 1 35 2
               50 0 53 2
               40 1 52 2
              480 0 68 2
               40 1 50 2
        13.333333 1 57 2
              700 1 63 2
               60 1 47 2
              180 1 41 2
              240 1 32 2
              126 1 36 2
              180 1 42 2
            56.25 1 58 2
               60 1 29 1
              150 1 37 2
              420 1 41 2
              760 1 43 2
              110 1 34 2
               90 1 47 2
         8.333333 1 67 1
              100 1 40 3
              180 1 50 1
             37.5 1 47 2
              148 0 42 2
              150 1 75 1
         362.6667 1 47 2
              455 1 29 2
              420 1 45 2
              150 1 65 2
               30 1 40 2
               30 1 65 2
              150 1 30 2
               30 1 69 1
               30 1 25 3
               75 1 58 1
              120 1 70 1
              390 1 65 2
              140 1 36 1
               50 1 47 1
              300 1 25 2
              500 1 47 1
               10 1 27 2
              200 0 32 1
               84 0 44 2
              210 0 33 2
               15 1 52 2
               72 0 60 4
              192 0 39 3
              100 0 68 2
               75 0 40 2
              120 0 43 2
              200 1 51 2
               80 0 42 2
               16 0 35 5
        166.66667 0 59 3
              100 1 46 2
              100 1 22 2
              120 1 71 2
        133.33333 1 59 3
              200 0 71 1
               60 1 76 1
              120 1 57 2
               60 1 56 2
              120 1 60 2
              130 0 39 2
           243.75 1 40 2
              120 1 53 2
               25 1 62 2
            112.5 1 30 2
               30 1 68 2
              105 1 62 2
              330 1 37 2
              150 1 27 2
              120 1 30 1
              165 0 47 2
               90 0 51 2
              150 1 33 2
        end
        label values sex sex
        label def sex 0 "Female", modify
        label def sex 1 "Male", modify
        label values educ educ
        label def educ 1 "No schooling", modify
        label def educ 2 "Primary", modify
        label def educ 3 "Secondary", modify
        label def educ 4 "Tertiary/University", modify
        label def educ 5 "Adult Educ", modify

        Comment


        • #5
          Look at your trace in detail -- at the top where the tempvars are created, and then where the error arises later on. I have no idea whether the problem is with your dataset or with the code.

          The error arises because of issues with a tempvar derived from the dependent (outcome) variable, "yield", not with variable "sex". See below. All values of yield are non-missing, so the tempvar y_s only has 1 category, not two.

          Code:
          . which qregsel
          d:\home\stephenj\ado\stbplus\q\qregsel.ado
          *! version 1.1 1April2020
          *! version 1.2 9September2020 - Simplifies syntax and changes how the estimatio
          > n is done
          *! version 1.3 11September2020 - Fix some issues regarding collinearity
          *! version 1.4 22September2020 - Fix issue with the syntax in the selection eq.
          
          .
          .
          . ta sex, missing
          
                  sex |      Freq.     Percent        Cum.
          ------------+-----------------------------------
               Female |         25       25.00       25.00
                 Male |         75       75.00      100.00
          ------------+-----------------------------------
                Total |        100      100.00
          
          . return list    
          
          scalars:
                            r(N) =  100
                            r(r) =  2
          
          .        
          . gen y_s = (yield!=.)
          
          . ta y_s, missing
          
                  y_s |      Freq.     Percent        Cum.
          ------------+-----------------------------------
                    1 |        100      100.00      100.00
          ------------+-----------------------------------
                Total |        100      100.00
          
          . return list
          
          scalars:
                            r(N) =  100
                            r(r) =  1
          
          .
          . qregsel yield age educ ///
          >         , select(sex) quantile(.5)
          __000001 should be binary.
          r(198);
          
          end of do-file
          
          r(198);
          
          .

          Comment


          • #6
            Stephen Jenkins am so grateful for the insights. I think the code needs to allow for some space to allow for non missings because not all the time we can have data with missing values. I have contacted the authors to help

            Comment

            Working...
            X