Announcement

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

  • boostrap for xtqreg

    Dear All, How can I test coefficients equality across different quantiles using xtqreg (Please install xtqreg).
    Code:
    webuse grunfeld, clear
    
    xtset company year
    
    xtqreg invest mvalue kstock, quantile(.25)
    xtqreg invest mvalue kstock, quantile(.75)
    In particular, I'd like to know if the estimate of mvalue when q=0.25 (quantile(.25)) is equal to the estimate of mvalue when q=0.75 (quantile(.75)). Any suggestion is appreciated.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    Using -bootstrap- with panel data is a bit tricky. The -xtset- settings of the data set can get in the way, and at the same time you have to assure that the panels are respected in the bootstrap sampling. The bold faced parts of the code below resolve these technical issues. The rest of the code is pretty straightforward bootstrapping.

    Code:
    webuse grunfeld, clear
    xtset, clear
    
    
    capture program drop xtq_diff
    program define xtq_diff, rclass
        xtset comp
        xtqreg invest mvalue kstock, quantile(.25)
        local b25 = _b[mvalue]
        xtqreg invest mvalue kstock, quantile(.75)
        local b75 = _b[mvalue]
        return scalar diff = `b75' - `b25'
        exit
    end
    
    bootstrap diff = r(diff), reps(50) cluster(company) idcluster(comp): xtq_diff
    Added: For replicable results, don't forget to set the seed for the random number generator.
    Last edited by Clyde Schechter; 05 Jan 2019, 22:48.

    Comment


    • #3
      Dear Clyde, Many thanks for the helpful suggestions. By the way, how can I explain to others the "xtset, clear" outside the program but "xtset comp" inside the program will make thing right? I.e., where can I find more references? Thanks.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        Well, I can't give you any references, but I can explain it. The grunfeld data set comes with -xtset company year- already done. When you do bootstrap resampling, you necessarily end up with repeated values of year within the resampled companies because the resampling is done with replacement. With that going on, Stata complains that you have violated the assumption that company and year uniquely identify observations in the data and the program breaks.

        It is precisely because of this problem that the -bootstrap- command has the -cluster()- and -idcluster()- options. The idea is to tell -bootstrap- what the panel variable is, so that whole panels are resampled, with replacement. Note that because panels are sampled with replacement, some panels will appear more than once in the resampled data (and others will be omitted). So that these are treated as if they were distinct clusters, they need to be identified by something other than the original panel identifier (company). That's why a separate variable to identify the resampled clusters is needed, and that's what the -idcluster()- option creates.

        Comment


        • #5
          Dear Clyde, Many thanks for this wonderful explanation. I think I have some idea about it.

          Ho-Chuan (River) Huang
          Stata 19.0, MP(4)

          Comment


          • #6
            Dear Clyde, Given your explanation, I wonder the following code is correct or not?
            Code:
            webuse grunfeld, clear
            xtset company year
            bootstrap, cl(company) r(100) id(id) seed(123): xtqreg invest mvalue kstock
            The problem is that, -xtqreg- command does not provide option on robust (clustered) standard errors (I have confirmed with the author of -xtqreg- command). As such, I think that I can use boostrapping procedure to do that. Do you think that the above command is OK for this purpose?
            Ho-Chuan (River) Huang
            Stata 19.0, MP(4)

            Comment


            • #7
              Yes, I would think so.

              Comment


              • #8
                Dear Clyde, Thanks.
                Ho-Chuan (River) Huang
                Stata 19.0, MP(4)

                Comment


                • #9
                  Dear both,

                  I have been trying to bootstrap clustered standard errors using bootstrap / xtqreg. In this context, I found your interesting exchange on the matter.
                  The problem is that when I use the bootstrap with xtqreg I get the Stata error message "r(100): varlist required" (see State code and output below).

                  Code:
                  . webuse grunfeld, clear
                  
                  .
                  . xtset company
                    panel variable:  company (balanced)
                  
                  .
                  . bootstrap, cl(company) r(100) id(id) seed(123): xtqreg invest mvalue kstock
                  (running xtqreg on estimation sample)
                  
                  Bootstrap replications (100)
                  ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
                  ..................................................    50
                  ..................................................   100
                  varlist required
                  r(100);
                  What surprises me is that the code works perfectly with other estimation commands such as xtreg. The error only shows up when I combine it with xtqreg.
                  I use Stata/MP 15.0

                  Any suggestions would be highly appreciated.

                  Best regards,
                  Sebastian

                  Comment


                  • #10
                    Dear Sebastian Hauptmeier,

                    Thanks for this. I am aware of that problem with xtqreg and it will be solved when I next update the command. If you email me I'll be happy to send you an updated version of the code that should solve this. Alternatively do the following:
                    Code:
                    capture bootstrap, cl(company) r(100) id(id) seed(123): xtqreg invest mvalue kstock
                    ereturn display
                    Best wishes,

                    Joao

                    Comment


                    • #11
                      Dear Joao,
                      Many thanks for the quick reply!
                      I just sent you an email.
                      Best,
                      Sebastian

                      Comment


                      • #12
                        Dear All,

                        The new version of xtqreg solves the bootstrap problem discussed above. Thanks to Kit Baum, the new version is now available in SSC.

                        Please do let me know if you find any problems with the updated command.

                        Best wishes,

                        Joao

                        Comment


                        • #13
                          Dear Joao, Thanks for this helpful message. However, I did not see any example(for using bootstrap) in the help file, or can I just use the above example?
                          Code:
                          webuse grunfeld, clear
                          xtset company
                          bootstrap, cl(company) r(100) id(id) seed(123): xtqreg invest mvalue kstock
                          Ho-Chuan (River) Huang
                          Stata 19.0, MP(4)

                          Comment


                          • #14
                            Dear River Huang,

                            Yes, that should work just fine.

                            Best wishes,

                            Joao

                            Comment


                            • #15
                              Dear Joao, Thanks for the reply. It indeed works. I just wonder if you are going to offer an illustrative (bootstrap) example in the help file of xtqreg.

                              Ho-Chuan (River) Huang
                              Stata 19.0, MP(4)

                              Comment

                              Working...
                              X