Announcement

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

  • Quantile Regression with time series operators

    Hello everyone,

    I was trying quantile regression on my dataset which was a panel dataset dealing with 2 years i.e. 2004 and 2011. I am trying to find out the relation between VAT tax rates in India and its effect on real monthly per capita consumption expenditure. Since VAT rates for 2004 = 0, it is now effectively a cross section dataset.

    I tried the command :
    qreg logRealMPCE VATrate i.year if ic==101 [pweight = weight], quantile (.25) to find out the effect of VAT on each quantile of the household. (ic is the code for each item of consumption).

    However, STATA says that factor variables and time series operators cannot be used. If I eliminate the weight and time variables, the results might not be accurate for my study. What should I do??

    Will really look forward to some help in this!!

    Thanks and regards,
    Meghna

    Last edited by Meghna Ghosh; 01 Nov 2018, 20:05.

  • #2
    First, it seems to me there is no reason for you to think you have to eliminate your weight. The error message says nothing about that, and the output of help qreg is quite clear that pweights are allowed.

    The error messages says you cannot use time series operators. The command you show does not have a time series operator. See the output of help tsvarlist for an explanation of what time series operators are.

    The error message says you cannot use factor variables. The has a factor variable operator on year (your i.year term). See the output of help fvvarlist for an explanation of what factor variables are.

    Since your variable year takes on just the two values 2004 and 2011, it effectively creates two indicator ("dummy") variables for year=2004 and year=2011. Because of collinearity, only one of those two will be used in your model, the other will be omitted.

    So you can avoid factor variables and manually create an indicator variable and use it in your model instead of i.year.

    I think the following will avoid the error message and give you the results you seek.
    Code:
    generate y2011 = year==2011
    qreg logRealMPCE VATrate y2011 if ic==101 [pweight = weight], quantile (.25)

    Comment


    • #3
      Originally posted by William Lisowski View Post
      First, it seems to me there is no reason for you to think you have to eliminate your weight. The error message says nothing about that, and the output of help qreg is quite clear that pweights are allowed.

      The error messages says you cannot use time series operators. The command you show does not have a time series operator. See the output of help tsvarlist for an explanation of what time series operators are.

      The error message says you cannot use factor variables. The has a factor variable operator on year (your i.year term). See the output of help fvvarlist for an explanation of what factor variables are.

      Since your variable year takes on just the two values 2004 and 2011, it effectively creates two indicator ("dummy") variables for year=2004 and year=2011. Because of collinearity, only one of those two will be used in your model, the other will be omitted.

      So you can avoid factor variables and manually create an indicator variable and use it in your model instead of i.year.

      I think the following will avoid the error message and give you the results you seek.
      Code:
      generate y2011 = year==2011
      qreg logRealMPCE VATrate y2011 if ic==101 [pweight = weight], quantile (.25)
      Thanks William!!
      However, on running this command, Stata pops up the error message saying that 'pweight not allowed'. The factor variable problem seems to be resolved for the time being.

      Comment


      • #4
        Perhaps the [pweight = weight] needs to come before the if clause? What does the output of help qreg suggest?

        Comment


        • #5
          Originally posted by William Lisowski View Post
          Perhaps the [pweight = weight] needs to come before the if clause? What does the output of help qreg suggest?
          The output of help qreg says that weight is after the if. I tried placing it before the if clause as well, but am getting the same error.

          Comment


          • #6
            What version of qreg do you have? You can check using

            Code:
            which qreg
            The last update was 28 July 2015 which means that earlier versions may have not supported weights or factor variables.

            Code:
            . sysuse auto
            (1978 Automobile Data)
            
            . qreg price weight length i.foreign if rep78<4 [pw=mpg], quantile(.25)
            Iteration  1:  WLS sum of weighted deviations =  425208.11
            
            Iteration  1: sum of abs. weighted deviations =  1595338.2
            Iteration  2: sum of abs. weighted deviations =  379630.24
            Iteration  3: sum of abs. weighted deviations =  329859.68
            Iteration  4: sum of abs. weighted deviations =  329673.33
            
            .25 Quantile regression                             Number of obs =         40
              Raw sum of deviations 398209.3 (about 4099)
              Min sum of deviations 329673.3                    Pseudo R2     =     0.1721
            
            ------------------------------------------------------------------------------
                         |               Robust
                   price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  weight |    1.85671   .2935737     6.32   0.000     1.261315    2.452105
                  length |  -3.675325   9.437875    -0.39   0.699    -22.81622    15.46557
                         |
                 foreign |
                Foreign  |   1714.004   1304.029     1.31   0.197      -930.69    4358.699
                   _cons |  -781.0693   2372.904    -0.33   0.744    -5593.542    4031.403
            ------------------------------------------------------------------------------
            
            . which qreg
            C:\Program Files (x86)\Stata15\ado\base\q\qreg.ado
            *! version 4.3.2  28jul2015

            ADDED IN EDIT: Using version control, I can confirm that pweights do not work with Stata 12 but they do with Stata 13+

            Code:
            . version 12
            
            . qreg price weight length i.foreign if rep78<4 [pw=mpg], quantile(.25)
            pweights not allowed
            r(101);
            Last edited by Andrew Musau; 02 Nov 2018, 04:04.

            Comment


            • #7
              In light of Andrew's advice about Stata in post #6, let me add some advice about Statalist.

              Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

              Section 11 advises
              11. What should I say about the version of Stata I use?

              The current version of Stata is 15.1. Please specify if you are using an earlier version; otherwise, the answer to your question may refer to commands or features unavailable to you.
              Section 12.1 is particularly pertinent

              12.1 What to say about your commands and your problem

              Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
              as Andrew presented his work in post #6. Section 12.3 advises the use of code delimiters [CODE] and [/CODE] to present code and output copied and pasted from the Do-file Editor or the Results window, as Andrew did.

              The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

              To document exactly what version of Stata you are using, use the about command.
              Code:
              . about
              
              Stata/SE 15.1 for Mac (64-bit Intel)
              Revision 15 Oct 2018
              I note that my advice in post #2 on avoiding factor variables is unnecessary in the latest versions of Stata, as Andrew demonstrated.

              Finally, from your earlier topic on quantile regression

              https://www.statalist.org/forums/for...ession-command

              I was trying regress logRealMPCE VATrate i.year if ic==101 & quintile1==1 [pweight = weight], vce(cluster state) initially. However, the problem was the VAT rates were getting dropped for quintile 1 and State quintile 1 if I am using this command. STATA says the VAT rates are omitted due to collinearity. Then I tried using qreg instead of regress. The same problem arises there too.
              But this suggests that the qreg command in that case did not exhibit any of the behavior you document in this topic. What changed?


              Comment


              • #8
                I also suggest reading the FAQ; in particular, putting your code example within CODE blocks makes it much easier to read;

                that is relevant here because it appears, in #1, that there is a space between "quantile" and "(" and that, I think, is not allowed

                Comment


                • #9
                  Originally posted by Andrew Musau View Post
                  What version of qreg do you have? You can check using

                  Code:
                  which qreg
                  The last update was 28 July 2015 which means that earlier versions may have not supported weights or factor variables.

                  Code:
                  . sysuse auto
                  (1978 Automobile Data)
                  
                  . qreg price weight length i.foreign if rep78<4 [pw=mpg], quantile(.25)
                  Iteration 1: WLS sum of weighted deviations = 425208.11
                  
                  Iteration 1: sum of abs. weighted deviations = 1595338.2
                  Iteration 2: sum of abs. weighted deviations = 379630.24
                  Iteration 3: sum of abs. weighted deviations = 329859.68
                  Iteration 4: sum of abs. weighted deviations = 329673.33
                  
                  .25 Quantile regression Number of obs = 40
                  Raw sum of deviations 398209.3 (about 4099)
                  Min sum of deviations 329673.3 Pseudo R2 = 0.1721
                  
                  ------------------------------------------------------------------------------
                  | Robust
                  price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
                  -------------+----------------------------------------------------------------
                  weight | 1.85671 .2935737 6.32 0.000 1.261315 2.452105
                  length | -3.675325 9.437875 -0.39 0.699 -22.81622 15.46557
                  |
                  foreign |
                  Foreign | 1714.004 1304.029 1.31 0.197 -930.69 4358.699
                  _cons | -781.0693 2372.904 -0.33 0.744 -5593.542 4031.403
                  ------------------------------------------------------------------------------
                  
                  . which qreg
                  C:\Program Files (x86)\Stata15\ado\base\q\qreg.ado
                  *! version 4.3.2 28jul2015

                  ADDED IN EDIT: Using version control, I can confirm that pweights do not work with Stata 12 but they do with Stata 13+

                  Code:
                  . version 12
                  
                  . qreg price weight length i.foreign if rep78<4 [pw=mpg], quantile(.25)
                  pweights not allowed
                  r(101);
                  Thanks Andrew, I was using a stata 12 version which is why the pweights were not working perhaps. Thanks a lot!!

                  Comment


                  • #10
                    Originally posted by William Lisowski View Post
                    In light of Andrew's advice about Stata in post #6, let me add some advice about Statalist.

                    Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

                    Section 11 advises


                    Section 12.1 is particularly pertinent



                    as Andrew presented his work in post #6. Section 12.3 advises the use of code delimiters [CODE] and [/CODE] to present code and output copied and pasted from the Do-file Editor or the Results window, as Andrew did.

                    The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

                    To document exactly what version of Stata you are using, use the about command.
                    Code:
                    . about
                    
                    Stata/SE 15.1 for Mac (64-bit Intel)
                    Revision 15 Oct 2018
                    I note that my advice in post #2 on avoiding factor variables is unnecessary in the latest versions of Stata, as Andrew demonstrated.

                    Finally, from your earlier topic on quantile regression

                    https://www.statalist.org/forums/for...ession-command



                    But this suggests that the qreg command in that case did not exhibit any of the behavior you document in this topic. What changed?

                    Thanks for all the advice William, I will keep them in mind when I next post a topic on the forum.

                    Regarding my earlier topic, the data did not change at all and the earlier commands are still not working. However, when I tried the commands I have listed in #1, they are working in the new version of STATA. I suppose the earlier method of quantile regression had some problem which is why there were no substantive results.I was facing the same issue on applying qreg and regress both.

                    Comment


                    • #11
                      Originally posted by Rich Goldstein View Post
                      I also suggest reading the FAQ; in particular, putting your code example within CODE blocks makes it much easier to read;

                      that is relevant here because it appears, in #1, that there is a space between "quantile" and "(" and that, I think, is not allowed
                      Thanks for the advice Rich. I understand that on typing the commands like this, there might be a problem in the understanding of the exact code. However, regarding the command in #1, no there was no space bertween "quantile" and "(".

                      Comment

                      Working...
                      X