Announcement

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

  • How to solve "varlist not allowed" problem

    Dear All,
    I am trying to do decomposition analysis using DHS data. I wrote the command given below. But when I run the program, it is stopped and shows error message "varlist not allowed". Can anyone help me please to solve this problem?

    **concentration index_corrected version
    egen raw_rank= rank(quintile), unique
    sort raw_rank
    quietly sum v005
    gen wi=v005/r(sum)
    gen cusum=sum(wi)
    gen wj=cusum[_n-1]
    replace wj=0 if wj==.
    gen rank=wj+0.05*wi
    //drop raw_rank wi cumsum wj

    qui sum m17_1[aw=v005]
    scalar mean= r(mean)
    cor m17_1 rank [aw=v005], c
    sca c=(2/mean)*r(cov_12)
    sca list c
    sca CI=8*r(cov_12)
    //sca list c
    display "concentration index by convenient covariance method", CI

    **Computing the semi-elasticities, CI and contributions of each factor
    //clear matrix
    global X "quintile1 quintile2 quintile3 quintile4 quintile5 resd1 resd2"
    qui regress m17_1 $X [pw=v005]
    ***decomposition start here
    foreach x of global X {
    qui {
    sca b_'x'=_b['x']
    corr rank 'x' [pw=v005], c
    sca cov_'x'=r(cov_12)
    sum 'x' [pw=v005]
    sca elas_'x'= (b_'x'*r(mean))/m_y
    sca CI_'x'=2*cov_'x'/r(mean)
    sca con_'x'= elas_'x'*CI_'x'
    sca prcnt_'x'= con_'x'/CI
    }
    di "'x' elasticity:", elas_'x'
    di "'x' concentration index:'", CI_'x'
    di "'x' contribution:", con_'x'
    di "'x' percentage contribution:", prcnt_'x'
    }

  • #2
    Try setting trace on. It should show where the problem lies.

    For more information, type
    Code:
    help trace
    at Stata's command line.

    Comment


    • #3
      Thank you Joseph Coveney. I used trace on command. The problem is soon afeter the decompostion start.

      sca b_'x'=_b['x']
      varlist not allowed
      Your further suggesation must appreciate.

      Comment


      • #4
        Originally posted by Sumon Khan View Post
        Your further suggesation must appreciate.
        Examine the trace. It will show the macros expanded in each executed line. If the problem is not obvious from that, then set the trace depth deeper until you see the line where a variable list is not appropriate in the context.

        Comment


        • #5
          You need different punctuation for local macros: left single quote -- macro name -- right single quote. I am replying by phone and can't illustrate directly.

          Comment


          • #6
            Thanks, Nick.

            Here's an illustration.

            Change
            Code:
            sca b_'x'=_b['x']
            to
            Code:
            scalar define b_`x' = _b[`x']

            Comment


            • #7
              Originally posted by Joseph Coveney View Post
              Thanks, Nick.

              Here's an illustration.

              Change
              Code:
              sca b_'x'=_b['x']
              to
              Code:
              scalar define b_`x' = _b[`x']

              Many thanks Joseph. The problem is solved now. However, when I try to see the result then another problem arise. I am quite new in stata. Please let me know the the process of getting result of elasticity, concentration index, contribution, percentage contribution against each variable. I copy pasted my full command again.
              **concentration index_corrected version
              egen raw_rank= rank(quintile), unique
              sort raw_rank
              quietly sum v005
              gen wi=v005/r(sum)
              gen cusum=sum(wi)
              gen wj=cusum[_n-1]
              replace wj=0 if wj==.
              gen rank=wj+0.05*wi
              //drop raw_rank wi cumsum wj

              qui sum m17_1[aw=v005]
              scalar mean= r(mean)
              cor m17_1 rank [aw=v005], c
              sca c=(2/mean)*r(cov_12)
              sca list c
              sca CI=8*r(cov_12)
              //sca list c
              display "concentration index by convenient covariance method", CI

              **Computing the semi-elasticities, CI and contributions of each factor
              clear matrix
              global x "quintile resd"
              //global xvar "quintile1 quintile2 quintile3 quintile4 quintile5 resd1 resd2"
              qui regress m17_1 $x [aw=v005]
              sum m17_1 [aw=v005]
              sca m_m17_1 =r(mean)
              ***decomposition start here
              foreach x of global xvar {
              qui {
              scalar define b_`x' = _b[`x']
              corr rank 'x' [aw=v005], c
              sca cov_'x'=r(cov_12)
              sum 'x' [pw=v005]
              sca elas_'x'= (b_'x'*r(mean))/m_y
              sca CI_'x'=2*cov_'x'/r(mean)
              sca con_'x'= elas_'x'*CI_'x'
              sca prcnt_'x'= con_'x'/CI
              }
              di "'x' elasticity:", elas_'x'
              di "'x' concentration index:'", CI_'x'
              di "'x' contribution:", con_'x'
              di "'x' percentage contribution:", prcnt_'x'
              }
              matrix Aaa = nullmat(Aaa)
              matrix rownames Aaa= $X
              matrix colnames Aaa = "Elasticity""CI""Absolute""%"
              matrix list Aaa, format(%8.4f)

              I look forward to your reply.

              Comment


              • #8
                Originally posted by Sumon Khan View Post
                when I try to see the result then another problem arise.
                What is it?

                Comment


                • #9
                  Originally posted by Joseph Coveney View Post

                  What is it?
                  Sorry Joseph, I was not clear in my last message. I found the analysis is working and interesting.
                  I have three more questions:
                  1. If I want to do decomposition analysis for more than one variable such as education, residence, and region, can I run the command 'conindex contuse [pw=wt], rankvar(v190) bounded limits(0
                  2. In decomposition analysis, how can I get
                   Coefficient
                   Mean
                   Elasticity
                   Absolute contribution
                   Percentage contribution to Concentration index
                  3. I am also in need of sample command to compute Gini Index and Gini Curve to see the geographic inequality.
                  Thank you very much for guidance.

                  Comment


                  • #10
                    Sorry, this isn't my field of study, but maybe some of the others on the list can help with your discipline-specific questions.

                    Comment


                    • #11
                      Hello Khan

                      I got similar errors and troubles, but I could solve all
                      Please try to copy and past what below

                      --------------------------------------------------------------
                      *First Calculate CI
                      *1- the data must be weighted, The weighted fractional rank be generated using glcurve as follows:

                      egen raw_rank=rank(v190), unique
                      sort raw_rank
                      quietly sum v005
                      gen wi=v005/r(sum)
                      gen cusum=sum(wi)
                      gen wj=cusum[_n-1]
                      replace wj=0 if wj==.
                      gen rank=wj+0.5*wi

                      *2- calculate Concentration Index
                      qui sum hw70 [fw=v005]
                      scalar mean=r(mean)
                      cor hw70 rank [fw=v005], c /* Error numerical overflow*/
                      sca c=(2/mean)*r(cov_12)
                      sca list c

                      *OR

                      qui sum rank [fw=v005]
                      sca var_rank=r(Var)
                      gen lhs=2*var_rank*(hw70/mean)
                      regr lhs rank [pw=v005]
                      sca c=_b[rank]
                      sca list c

                      *3- generate global X 'varlist' contains all regressors
                      global X "v107 v702 v716 v191 m1 m14"
                      qui regr hw70 $X [pw=v005]
                      sum hw70 [aw=v005]
                      sca m_hw70=r(mean)

                      *4- Finally, Decompose CI and contibution of each regressor or factor

                      set trace on
                      foreach X of global X {
                      qui {
                      scal b_`X'=_b[`X']
                      corr rank `X' [aw=v005], c
                      sca cov_`X'=r(cov_12)
                      sum `X' [aw=v005]
                      sca elas_`X'=(b_`X'*r(mean))
                      sca CI_`X'=8*cov_`X'
                      sca CI_`X' = 2*cov_`X'/r(mean)
                      sca con_`X'=4*(elas_`X'*CI_`X')
                      sca prcnt_`X'=(con_`X'/CI_`X')*100
                      }
                      di "`X' elasticity:", elas_`X'
                      di "`X' concentration index:", CI_`X'
                      di "`X' contribution:", con_`X'
                      di "`X' percentage contribution:", prcnt_`X'
                      matrix Aaa = nullmat(Aaa) \ ///
                      (elas_`X', CI_`X', con_`X', prcnt_`X')
                      }
                      matrix rownames Aaa= $X
                      matrix colnames Aaa = "Elasticity""CI""Absolute""%"
                      matrix list Aaa, format(%8.4f)
                      --------------------------------------------------------------

                      All the best

                      Comment


                      • #12
                        Hello Embarika Farouk ,

                        I have used your code But stata provides error regarding the estimation OF CI :
                        CI not found
                        r(111);
                        Do you please how can i solve the problem

                        Comment


                        • #13
                          #12 You need to tell us more about your data and code. For example, in #11 there is code

                          Code:
                          global X "v107 v702 v716 v191 m1 m14"
                          It seems unlikely that you have the same variables.

                          Comment


                          • #14
                            Hello Nick i m trying to analyze the inequality in Utilization of health Care using the concentrtion index , So my variable of intrest takes 1 if the households did a medical consultation, 0 otherwise .I used the package provided in "Analyzing Health Equity Using Household Survey Data" and the code blow. as i have a binary variable i should run a probit however i get this error r ambiguous abbreviation. Can you please help me

                            qui probit consultation $X $Z [pw=hhw]
                            foreach z of global Z {
                            gen copy_`z'=`z'
                            qui sum `z' [aw=hhw]
                            replace `z' = r(mean)
                            }
                            predict yhat
                            foreach z of global Z {
                            replace `z' = copy_`z'
                            drop copy_`z'
                            }
                            *sum m_yhat [aw=hhw]
                            gen yst = y-yhat + r(mean)

                            dprobit consultation $X $Z [pw=hhw]
                            matrix dfdx=e(dfdx)


                            sca need=0
                            foreach x of global X {
                            qui {
                            mat b_`X' = dfdx[1,"`X'"]
                            sca b_`X' = b_`X'[1,1]
                            corr r `X' [fw=hhw], c
                            sca cov_`X' = r(cov_12)
                            sum `X' [aw=hhw]
                            sca m_`X' = r(mean)
                            sca elas_`X' = (b_`X'*m_`X')/m_y
                            sca CI_`X' = 2*cov_`X'/m_`X'
                            sca con_`X' = elas_`X'*CI_`X'
                            sca prcnt_`X' = con_`X'/CI
                            sca need=need+con_`X'
                            }
                            di "`X' elasticity:", elas_`X'
                            di "`X' concentration index:", CI_`X'
                            di "`X' contribution:", con_`X'
                            di "`X' percentage contribution:", prcnt_`X'
                            }
                            di "Inequality due to need factors:", need
                            di "Inequality due to non-need factors:", nonneed
                            sca HI = CI - need
                            di "Horizontal Inequity Index:", HI
                            Last edited by Meriem OUD; 07 Mar 2019, 06:19.

                            Comment


                            • #15
                              Originally posted by Nick Cox View Post
                              #12 You need to tell us more about your data and code. For example, in #11 there is code

                              Code:
                              global X "v107 v702 v716 v191 m1 m14"
                              It seems unlikely that you have the same variables.
                              Hello Nick i m trying to analyze the inequality in Utilization of health Care using the concentrtion index , So my variable of intrest takes 1 if the households did a medical consultation, 0 otherwise .I used the package provided in "Analyzing Health Equity Using Household Survey Data" and the code blow. as i have a binary variable i should run a probit however i get this error r ambiguous abbreviation. Can you please help me

                              qui probit consultation $X $Z [pw=hhw]
                              foreach z of global Z {
                              gen copy_`z'=`z'
                              qui sum `z' [aw=hhw]
                              replace `z' = r(mean)
                              }
                              predict yhat
                              foreach z of global Z {
                              replace `z' = copy_`z'
                              drop copy_`z'
                              }
                              *sum m_yhat [aw=hhw]
                              gen yst = y-yhat + r(mean)

                              dprobit consultation $X $Z [pw=hhw]
                              matrix dfdx=e(dfdx)


                              sca need=0
                              foreach x of global X {
                              qui {
                              mat b_`X' = dfdx[1,"`X'"]
                              sca b_`X' = b_`X'[1,1]
                              corr r `X' [fw=hhw], c
                              sca cov_`X' = r(cov_12)
                              sum `X' [aw=hhw]
                              sca m_`X' = r(mean)
                              sca elas_`X' = (b_`X'*m_`X')/m_y
                              sca CI_`X' = 2*cov_`X'/m_`X'
                              sca con_`X' = elas_`X'*CI_`X'
                              sca prcnt_`X' = con_`X'/CI
                              sca need=need+con_`X'
                              }
                              di "`X' elasticity:", elas_`X'
                              di "`X' concentration index:", CI_`X'
                              di "`X' contribution:", con_`X'
                              di "`X' percentage contribution:", prcnt_`X'
                              }
                              di "Inequality due to need factors:", need
                              di "Inequality due to non-need factors:", nonneed
                              sca HI = CI - need
                              di "Horizontal Inequity Index:", HI

                              Comment

                              Working...
                              X