Announcement

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

  • grqreg with caterogical variables

    Dear all, I have seen a many similar posts regarding -grqreg- and the need for Stata 8.2, however none of the solutions I have seen seemed to help.

    My quantile regression and error is as follows:

    Code:
    qreg lgross lmovielikes lcastlikes lbudget imdb_score content_rating i.release_year i.is_*
    
    Median regression                                   Number of obs =      1,206
      Raw sum of deviations 978.6617 (about 17.369829)
      Min sum of deviations 604.6847                    Pseudo R2     =     0.3821
    
    ----------------------------------------------------------------------------------
              lgross |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -----------------+----------------------------------------------------------------
         lmovielikes |   .6965486    .045184    15.42   0.000     .6078977    .7851996
          lcastlikes |   .0754692   .0299883     2.52   0.012     .0166323    .1343061
             lbudget |   .6336533    .038595    16.42   0.000     .5579299    .7093766
          imdb_score |  -.1318835   .0535796    -2.46   0.014    -.2370067   -.0267603
      content_rating |  -.1368002   .0452726    -3.02   0.003    -.2256249   -.0479754
                     |
        release_year |
               2005  |  -.5393104   .2245125    -2.40   0.016    -.9798037    -.098817
               2006  |  -.1452418    .211552    -0.69   0.493    -.5603066     .269823
               2007  |  -.4913684   .2302747    -2.13   0.033    -.9431672   -.0395697
               2008  |  -.2643716   .2312826    -1.14   0.253    -.7181479    .1894047
               2009  |  -.5044308   .2210407    -2.28   0.023    -.9381124   -.0707492
               2010  |  -1.020448   .2239698    -4.56   0.000    -1.459877   -.5810196
               2011  |  -1.250379   .2207908    -5.66   0.000     -1.68357   -.8171878
               2012  |  -1.321453     .22278    -5.93   0.000    -1.758547   -.8843591
               2013  |  -1.403902   .2242945    -6.26   0.000    -1.843968   -.9638367
               2014  |  -1.063269   .2275361    -4.67   0.000    -1.509695   -.6168439
               2015  |  -1.314635   .2310188    -5.69   0.000    -1.767893   -.8613763
               2016  |  -.9949853    .270145    -3.68   0.000     -1.52501    -.464961
                     |
         1.is_Action |  -.1017312   .1180044    -0.86   0.389    -.3332557    .1297932
      1.is_Adventure |  -.1067062   .1243318    -0.86   0.391     -.350645    .1372326
      1.is_Animation |   .0477546   .2141952     0.22   0.824    -.3724962    .4680054
         1.is_Comedy |   .2693157   .1080714     2.49   0.013     .0572797    .4813516
      1.is_Biography |   .1165475   .1760974     0.66   0.508    -.2289554    .4620504
          1.is_Crime |  -.1442738   .1261661    -1.14   0.253    -.3918115    .1032639
    1.is_Documentary |   -.133719   .4140995    -0.32   0.747    -.9461817    .6787437
          1.is_Drama |  -.3432234   .1070939    -3.20   0.001    -.5533414   -.1331054
         1.is_Family |   .3020588   .1799942     1.68   0.094    -.0510896    .6552072
        1.is_Fantasy |  -.3180427   .1264445    -2.52   0.012    -.5661266   -.0699588
        1.is_History |  -.2177074    .229903    -0.95   0.344    -.6687768    .2333621
         1.is_Horror |   .2168299   .1585732     1.37   0.172    -.0942907    .5279504
          1.is_Music |   .3216573   .2389344     1.35   0.178    -.1471317    .7904463
        1.is_Musical |  -.5954019    .363013    -1.64   0.101    -1.307633    .1168291
        1.is_Mystery |   .0115044   .1430008     0.08   0.936     -.269063    .2920718
        1.is_Romance |  -.0451323   .1090726    -0.41   0.679    -.2591325    .1688679
          1.is_SciFi |  -.2480878   .1291382    -1.92   0.055    -.5014568    .0052811
          1.is_Sport |   .0040368   .2104517     0.02   0.985    -.4088692    .4169428
       1.is_Thriller |  -.0173475   .1150452    -0.15   0.880    -.2430661    .2083711
            1.is_War |  -.2832183   .2126836    -1.33   0.183    -.7005032    .1340667
        1.is_Western |  -.2848919   .3898555    -0.73   0.465    -1.049788    .4800041
               _cons |   2.102454   .7290744     2.88   0.004     .6720106    3.532897
    ----------------------------------------------------------------------------------
    
    . grqreg, cons ci ols olsci
    2b.release_year invalid name
    r(198);
    Remedies I have tried -xi- and specifying that varlist for the grqreg command doesn't include the indicators, however even in that case, the same invalid name error returns. Any advice on this would be greatly appreciated.

    Thank you
    Last edited by Curan Tahim; 28 Feb 2018, 15:25.

  • #2
    grqreg is from SSC, as you are asked to explain. That's a program written for Stata 8.2, so it won't understand factor variable notation, which was introduced later. I think this point has often been made on Statalist, but at this moment I am too lazy to search for references.

    You're commenting elsewhere

    https://www.reddit.com/r/stata/comme...cal_variables/

    that no-one answered your question here, but possible reasons are that you give no example data that anyone can use and you don't show the code that didn't work. So, that's all hard to discuss. Your current dataset is too big to post here easily, but you should be able to replicate a problem with some of the observations and some of the variables.

    But this worked for me.

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . xi : qreg mpg i.rep78
    i.rep78           _Irep78_1-5         (naturally coded; _Irep78_1 omitted)
    Iteration  1:  WLS sum of weighted deviations =  137.84566
    
    Iteration  1: sum of abs. weighted deviations =      135.5
    note:  alternate solutions exist
    Iteration  2: sum of abs. weighted deviations =      135.5
    
    Median regression                                   Number of obs =         69
      Raw sum of deviations    153.5 (about 20)
      Min sum of deviations    135.5                    Pseudo R2     =     0.1173
    
    ------------------------------------------------------------------------------
             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
       _Irep78_2 |         -6     5.8648    -1.02   0.310    -17.71628    5.716284
       _Irep78_3 |         -5    5.41767    -0.92   0.360    -15.82304    5.823039
       _Irep78_4 |         -2   5.529386    -0.36   0.719    -13.04622    9.046218
       _Irep78_5 |          6   5.702608     1.05   0.297    -5.392269    17.39227
           _cons |         24   5.245636     4.58   0.000     13.52064    34.47936
    ------------------------------------------------------------------------------
    
    . grqreg , cons ci ols olsci
    (Believe me that graphs did appear.)

    That said, one wild guess is that you're guessing or assuming that xi: understands current factor variable notation, but it predates the latter and doesn't (didn't) use all of the same notation. This is all evident by comparing the help for xi: with documentation on factor variable notation.

    If this doesn't help, then I think you need to show the code that didn't work, and it will be easier if you use a dataset that everyone can use.
    Last edited by Nick Cox; 01 Mar 2018, 12:11.

    Comment


    • #3
      Try unabbreviating your factor variable list:

      Code:
      sysuse auto, clear
      fvunab rhs: weight length i.f* i.rep*
      xi: qreg price `rhs'
      grqreg, cons ci ols olsci
      -xi- does not know what to do with the wildcard in i.is_*.
      Last edited by Dimitriy V. Masterov; 01 Mar 2018, 11:41.

      Comment


      • #4
        Thanks to both for the reply. Dimitriy's solution worked well for me.

        I was wondering whether the quantile regression plot would show different results when the sample was split by the dummy variable lowrate, which can be 0 or 1.

        Code:
        fvunab rhs: lmovielikes lcastlikes lbudget i.content_rating i.release_year i.is_*
        xi : qreg lgross `rhs' if lowrate == 1
        
        Median regression                                   Number of obs =        559
          Raw sum of deviations 443.8905 (about 17.216612)
          Min sum of deviations  260.258                    Pseudo R2     =     0.4137
        
        --------------------------------------------------------------------------------
                lgross |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        ---------------+----------------------------------------------------------------
           lmovielikes |    .818738   .0669362    12.23   0.000     .6872376    .9502385
            lcastlikes |   .0321035   .0478582     0.67   0.503    -.0619169    .1261239
               lbudget |   .5916304   .0672178     8.80   0.000     .4595767    .7236841
         _Icontent_r_4 |          0  (omitted)
         _Icontent_r_5 |  -4.529139   .7658236    -5.91   0.000    -6.033648    -3.02463
         _Icontent_r_6 |  -.2473609     .47817    -0.52   0.605    -1.186756    .6920342
         _Icontent_r_7 |  -.1045492   .5689705    -0.18   0.854    -1.222328    1.013229
         _Icontent_r_8 |  -.7174808   .5755127    -1.25   0.213    -1.848112    .4131502
        _Icontent_r_11 |  -3.529099   .9791832    -3.60   0.000    -5.452767   -1.605432
         _Irelease_y_3 |   -.492393   .3051561    -1.61   0.107    -1.091891    .1071053
         _Irelease_y_4 |  -.3011319   .2886425    -1.04   0.297    -.8681883    .2659245
         _Irelease_y_5 |  -.5974169   .3313404    -1.80   0.072    -1.248356    .0535222
         _Irelease_y_6 |   -.235301   .3192528    -0.74   0.461    -.8624932    .3918913
         _Irelease_y_7 |  -.9083938   .3285989    -2.76   0.006    -1.553947   -.2628406
         _Irelease_y_8 |  -1.445452   .3343462    -4.32   0.000    -2.102297   -.7886082
         _Irelease_y_9 |  -1.992626   .3466535    -5.75   0.000    -2.673648   -1.311603
        _Irelease_y_10 |    -1.8776   .3451882    -5.44   0.000    -2.555744   -1.199456
        _Irelease_y_11 |  -2.407172     .35557    -6.77   0.000    -3.105711   -1.708632
        _Irelease_y_12 |  -1.943543    .344051    -5.65   0.000    -2.619453   -1.267633
        _Irelease_y_13 |  -2.429431   .3568638    -6.81   0.000    -3.130512   -1.728349
        _Irelease_y_14 |  -1.677132   .4042336    -4.15   0.000    -2.471275   -.8829898
         _Iis_Action_1 |  -.3918549   .1676227    -2.34   0.020    -.7211603   -.0625496
         _Iis_Advent_1 |  -.1878955   .1793565    -1.05   0.295    -.5402526    .1644615
         _Iis_Animat_1 |   .2349444   .3327185     0.71   0.480     -.418702    .8885908
         _Iis_Comedy_1 |   .2377924   .1676635     1.42   0.157    -.0915931     .567178
         _Iis_Biogra_1 |  -.1124344   .4364182    -0.26   0.797    -.9698055    .7449367
          _Iis_Crime_1 |   .0831356   .1937351     0.43   0.668    -.2974693    .4637404
         _Iis_Docume_1 |   .0751888    1.05062     0.07   0.943     -1.98882    2.139197
          _Iis_Drama_1 |  -.1770135   .1425048    -1.24   0.215    -.4569732    .1029462
         _Iis_Family_1 |   .5578624   .3415111     1.63   0.103    -.1130577    1.228783
         _Iis_Fantas_1 |  -.4572793    .171926    -2.66   0.008    -.7950388   -.1195199
         _Iis_Histor_1 |  -.5548033   .4947843    -1.12   0.263    -1.526838    .4172316
         _Iis_Horror_1 |   .4706961   .1992695     2.36   0.019     .0792187    .8621736
          _Iis_Music_1 |  -.3430642   .3439626    -1.00   0.319      -1.0188     .332672
         _Iis_Musica_1 |  -.5732825   .5139168    -1.12   0.265    -1.582905    .4363396
         _Iis_Myster_1 |  -.3230991   .2113672    -1.53   0.127    -.7383434    .0921451
         _Iis_Romanc_1 |  -.1756094   .1576042    -1.11   0.266    -.4852328     .134014
          _Iis_SciFi_1 |  -.2190414   .1930998    -1.13   0.257    -.5983982    .1603153
          _Iis_Sport_1 |  -.3287085    .324206    -1.01   0.311    -.9656316    .3082146
         _Iis_Thrill_1 |  -.1678866   .1748385    -0.96   0.337    -.5113678    .1755946
            _Iis_War_1 |  -.6644983   .3645124    -1.82   0.069    -1.380606    .0516094
         _Iis_Wester_1 |  -.0827323   .5146735    -0.16   0.872    -1.093841    .9283763
                 _cons |   1.429675   1.155483     1.24   0.217    -.8403453    3.699695
        --------------------------------------------------------------------------------
        
         grqreg, cons ci ols olsci
        o._Icontent_r_4 invalid name
        r(198);
        I assume this error occurs due to the fact that when the model is split, there are no observations for one of the content indicators. How should I troubleshoot this? The error occurs even when varlist excludes the indicator variables.

        Thanks!

        Comment


        • #5
          To provide some update, I have attempted to use -if- commands to avoid the estimation of content_rating = 4 but cannot avoid the error when using -grqreg-. Is there any further advice that can be offered please?

          Comment


          • #6
            Answered here.

            Comment


            • #7
              Originally posted by Nick Cox View Post
              grqreg is from SSC, as you are asked to explain. That's a program written for Stata 8.2, so it won't understand factor variable notation, which was introduced later. I think this point has often been made on Statalist, but at this moment I am too lazy to search for references.

              You're commenting elsewhere

              https://www.reddit.com/r/stata/comme...cal_variables/

              that no-one answered your question here, but possible reasons are that you give no example data that anyone can use and you don't show the code that didn't work. So, that's all hard to discuss. Your current dataset is too big to post here easily, but you should be able to replicate a problem with some of the observations and some of the variables.

              But this worked for me.

              Code:
              . sysuse auto, clear
              (1978 Automobile Data)
              
              . xi : qreg mpg i.rep78
              i.rep78 _Irep78_1-5 (naturally coded; _Irep78_1 omitted)
              Iteration 1: WLS sum of weighted deviations = 137.84566
              
              Iteration 1: sum of abs. weighted deviations = 135.5
              note: alternate solutions exist
              Iteration 2: sum of abs. weighted deviations = 135.5
              
              Median regression Number of obs = 69
              Raw sum of deviations 153.5 (about 20)
              Min sum of deviations 135.5 Pseudo R2 = 0.1173
              
              ------------------------------------------------------------------------------
              mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval]
              -------------+----------------------------------------------------------------
              _Irep78_2 | -6 5.8648 -1.02 0.310 -17.71628 5.716284
              _Irep78_3 | -5 5.41767 -0.92 0.360 -15.82304 5.823039
              _Irep78_4 | -2 5.529386 -0.36 0.719 -13.04622 9.046218
              _Irep78_5 | 6 5.702608 1.05 0.297 -5.392269 17.39227
              _cons | 24 5.245636 4.58 0.000 13.52064 34.47936
              ------------------------------------------------------------------------------
              
              . grqreg , cons ci ols olsci
              (Believe me that graphs did appear.)

              That said, one wild guess is that you're guessing or assuming that xi: understands current factor variable notation, but it predates the latter and doesn't (didn't) use all of the same notation. This is all evident by comparing the help for xi: with documentation on factor variable notation.

              If this doesn't help, then I think you need to show the code that didn't work, and it will be easier if you use a dataset that everyone can use.

              Just curious, all the coefficients are integers, is it a normal situation for categorical variables?

              Best wishes
              Last edited by Hark Huang; 29 Oct 2020, 07:21.

              Comment


              • #8
                I think the point is that the response mpg -- although in principle continuous -- is reported as integers. The coefficients are measured on that scale.

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  I think the point is that the response mpg -- although in principle continuous -- is reported as integers. The coefficients are measured on that scale.
                  Thanks Nick. Just tried to replace the independent variable (i.rep78) with a continuous one (e.g. sales), the coefficient became non-integer, I suppose it's just the nature of regression although mpg is still measured on the same scale?

                  Comment


                  • #10
                    The units and dimensions change. When a predictor is an indicator variable, the units of the coefficient are those of the outcome; otherwise the units of the coefficient are units of outcome/units of predictor.

                    Comment


                    • #11
                      Originally posted by Nick Cox View Post
                      The units and dimensions change. When a predictor is an indicator variable, the units of the coefficient are those of the outcome; otherwise the units of the coefficient are units of outcome/units of predictor.
                      Thanks Nick, very clear : )

                      Comment


                      • #12
                        Dear all,

                        I am using qreg2 with clustered standard errors. The model specification includes categorical variables as regressors. However, I am unable to execute the grqreg command. Given below is the result:

                        Code:

                        quietly xi: qreg2 mpc_c time##treated i.Sector SexRatio c.Age##c.Age Dependency_Ratio i.HH_Type_N i.Religion_N i.Education_N i.Marital_Status_N i.Social_Group c.AvgMonsRainfall##c.AvgMonsRainfall c.AverageTempMax##c.AverageTempMax AverageTempMaxSD AvgMonsRainfallSD shtotirrigatedarea BankSh electrify i.State_District trend if Relation==1 , cluster(hhid) quantile(.5)

                        grqreg, cons ci ols olsci

                        grqreg only works after qreg or bsqreg or sqreg
                        r(498);




                        Any help would be appreciated.

                        Comment


                        • #13
                          Hi Gaurv
                          try installing -qregplot- from SSC.
                          It works with qreg2 and will also allow you using categorical variables.
                          Although, it wont show you marginal effects, instead showing the interactions.
                          HTH

                          Comment

                          Working...
                          X