R - fixed effect of panel data analysis and robust standard errors











up vote
0
down vote

favorite












I am working with the panel data through plm package in R. And now I am considering a fixed effect model of group (cities), time, and two ways of group and time, respectively. Because I detected heteroskedasticity through the Breusch-Pagan test, I compute robust standard errors.



I read a help ?vcovHC, but I could not understand fully how to utilize coeftest.



My current code is:



library(plm)
library(lmtest)
library(sandwich)

fem_city <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "individual")
fem_year <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "time")
fem_both <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "twoways")

coeftest(fem_city, vcovHC(fem_city, type = 'HC3', cluster = 'group')
coeftest(fem_year, vcovHC(fem_city, type = 'HC3', cluster = 'time')


In order to compute the robust standard errors, are codes of coeftest appropriate? I am wondering that how to set the cluster option for effect = 'individual and effect = 'time' each.
For example, I set coeftest codes:



cluster = 'group' in plm of fem_city for effect = 'individual' in coeftest



cluster = 'time' in plm of fem_year for effect = 'time' in coeftest



Is this way appropriate?



And, how to compute the robust standard error for twoways of both city and year?



Thank you very much!










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am working with the panel data through plm package in R. And now I am considering a fixed effect model of group (cities), time, and two ways of group and time, respectively. Because I detected heteroskedasticity through the Breusch-Pagan test, I compute robust standard errors.



    I read a help ?vcovHC, but I could not understand fully how to utilize coeftest.



    My current code is:



    library(plm)
    library(lmtest)
    library(sandwich)

    fem_city <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "individual")
    fem_year <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "time")
    fem_both <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "twoways")

    coeftest(fem_city, vcovHC(fem_city, type = 'HC3', cluster = 'group')
    coeftest(fem_year, vcovHC(fem_city, type = 'HC3', cluster = 'time')


    In order to compute the robust standard errors, are codes of coeftest appropriate? I am wondering that how to set the cluster option for effect = 'individual and effect = 'time' each.
    For example, I set coeftest codes:



    cluster = 'group' in plm of fem_city for effect = 'individual' in coeftest



    cluster = 'time' in plm of fem_year for effect = 'time' in coeftest



    Is this way appropriate?



    And, how to compute the robust standard error for twoways of both city and year?



    Thank you very much!










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am working with the panel data through plm package in R. And now I am considering a fixed effect model of group (cities), time, and two ways of group and time, respectively. Because I detected heteroskedasticity through the Breusch-Pagan test, I compute robust standard errors.



      I read a help ?vcovHC, but I could not understand fully how to utilize coeftest.



      My current code is:



      library(plm)
      library(lmtest)
      library(sandwich)

      fem_city <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "individual")
      fem_year <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "time")
      fem_both <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "twoways")

      coeftest(fem_city, vcovHC(fem_city, type = 'HC3', cluster = 'group')
      coeftest(fem_year, vcovHC(fem_city, type = 'HC3', cluster = 'time')


      In order to compute the robust standard errors, are codes of coeftest appropriate? I am wondering that how to set the cluster option for effect = 'individual and effect = 'time' each.
      For example, I set coeftest codes:



      cluster = 'group' in plm of fem_city for effect = 'individual' in coeftest



      cluster = 'time' in plm of fem_year for effect = 'time' in coeftest



      Is this way appropriate?



      And, how to compute the robust standard error for twoways of both city and year?



      Thank you very much!










      share|improve this question















      I am working with the panel data through plm package in R. And now I am considering a fixed effect model of group (cities), time, and two ways of group and time, respectively. Because I detected heteroskedasticity through the Breusch-Pagan test, I compute robust standard errors.



      I read a help ?vcovHC, but I could not understand fully how to utilize coeftest.



      My current code is:



      library(plm)
      library(lmtest)
      library(sandwich)

      fem_city <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "individual")
      fem_year <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "time")
      fem_both <- plm (z ~ x+y, data = rawdata, index = c("city","year"), model = "within", effect = "twoways")

      coeftest(fem_city, vcovHC(fem_city, type = 'HC3', cluster = 'group')
      coeftest(fem_year, vcovHC(fem_city, type = 'HC3', cluster = 'time')


      In order to compute the robust standard errors, are codes of coeftest appropriate? I am wondering that how to set the cluster option for effect = 'individual and effect = 'time' each.
      For example, I set coeftest codes:



      cluster = 'group' in plm of fem_city for effect = 'individual' in coeftest



      cluster = 'time' in plm of fem_year for effect = 'time' in coeftest



      Is this way appropriate?



      And, how to compute the robust standard error for twoways of both city and year?



      Thank you very much!







      r plm standard-error robust






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 13:44









      Tjebo

      2,0971125




      2,0971125










      asked Nov 9 at 13:36









      Suralira.K

      51




      51
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Set cluster='group' if you want to cluster on the variable serving as the individual index (city in your example).



          Set cluster='time' if you want to cluster on the variable serving as the time index (yearin your example).



          You can cluster on the time index even for a fixed effects one-way individual model.



          For clustering on both index variables, you cannot do that with plm::vcovHC. Look at vcovDC from the same packages which provides double clustering (DC = double clustering), e.g.



          coeftest(fem_city, vcovDC(fem_city)






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226737%2fr-fixed-effect-of-panel-data-analysis-and-robust-standard-errors%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            Set cluster='group' if you want to cluster on the variable serving as the individual index (city in your example).



            Set cluster='time' if you want to cluster on the variable serving as the time index (yearin your example).



            You can cluster on the time index even for a fixed effects one-way individual model.



            For clustering on both index variables, you cannot do that with plm::vcovHC. Look at vcovDC from the same packages which provides double clustering (DC = double clustering), e.g.



            coeftest(fem_city, vcovDC(fem_city)






            share|improve this answer



























              up vote
              0
              down vote



              accepted










              Set cluster='group' if you want to cluster on the variable serving as the individual index (city in your example).



              Set cluster='time' if you want to cluster on the variable serving as the time index (yearin your example).



              You can cluster on the time index even for a fixed effects one-way individual model.



              For clustering on both index variables, you cannot do that with plm::vcovHC. Look at vcovDC from the same packages which provides double clustering (DC = double clustering), e.g.



              coeftest(fem_city, vcovDC(fem_city)






              share|improve this answer

























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                Set cluster='group' if you want to cluster on the variable serving as the individual index (city in your example).



                Set cluster='time' if you want to cluster on the variable serving as the time index (yearin your example).



                You can cluster on the time index even for a fixed effects one-way individual model.



                For clustering on both index variables, you cannot do that with plm::vcovHC. Look at vcovDC from the same packages which provides double clustering (DC = double clustering), e.g.



                coeftest(fem_city, vcovDC(fem_city)






                share|improve this answer














                Set cluster='group' if you want to cluster on the variable serving as the individual index (city in your example).



                Set cluster='time' if you want to cluster on the variable serving as the time index (yearin your example).



                You can cluster on the time index even for a fixed effects one-way individual model.



                For clustering on both index variables, you cannot do that with plm::vcovHC. Look at vcovDC from the same packages which provides double clustering (DC = double clustering), e.g.



                coeftest(fem_city, vcovDC(fem_city)







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 10 at 12:16

























                answered Nov 9 at 20:23









                Helix123

                1,585623




                1,585623






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53226737%2fr-fixed-effect-of-panel-data-analysis-and-robust-standard-errors%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Full-time equivalent

                    Bicuculline

                    さくらももこ