Announcement

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

  • cluster2 with fixed effect

    Dear statalisters,

    I am running cluster 2 , clustered by firm and year, but also need to include firm fixed effect. I used

    cluster2 capx x1 x2 i.firmid , fcluster(firmid) tcluster(year)

    got an error "factor variables and time-series operators not allowed"

    could you please let me know how i should include the fixed effect here?

    thanks,
    Rochelle

  • #2
    Rochelle,

    user-written commands usually do not support factor variables. Therefore, you have to generate the dummies yourself.
    Code:
    tab firmid, gen(fdum)
    cluster2 capx x1 x2 fdum*, fcluster(firmid) tcluster(year)
    should work.

    Best,
    Martin

    Comment


    • #3
      Alternatively, just use -reghdfe-, you can get it from SSC and it's simpler and faster when handling multiple FEs.

      Best,
      S

      Comment


      • #4
        Thank you Sergio !


        @ Martin, Thanks ! when I executte

        tab firmid, gen(fdum) I got an error message

        too many values
        r(134);

        my panel data has 33,315 observation and about 5000 firms.


        Best,

        Rochelle

        Comment


        • #5
          Sorry for getting back late. What kind of Stata version do you use? The maximum tabulate can handle ist: Small Stata: 500 rows, Stata/IC: 3000 rows, Stata/SE or MP: 12000 rows. I would assume that you do not have access to Stata/SE or MP then?

          Sergio's solution is probably best, though the 2-way clustering is not automated in reghdfe as far as I understand the help file. If it is necesseray, maybe you can demean the data manually before using the cluster2 command and leave out the firm fixed effects. Or, you can generate the dummies using e.g. a loop. Though, if you do not have access to Stata SE/MP, you still cannot do this since the maximum number of variables Stata/IC can handle is 2047.

          Thus, I would suggest you either implement Sergio's suggestion or post back here to let us know what version of Stata you have access to...

          Comment


          • #6
            Hi Martin,

            Just to clarify, you can do multiway clustering in reghdfe; I think the newer help file (github, not on ssc) is a bit more clear about it. The syntax is:

            Code:
            reghdfe varlist , absorb(fe1 fe2 ...) vce(cluster var1 var2 ..)
            In Rochelle's case it would be:

            Code:
            reghdfe capx x1 x2, absorb(firmid) vce(cluster firmid year)
            Also, since she is only using one set of FEs, she could even use xtivreg2.

            Cheers,
            Sergio

            Comment


            • #7
              Example with xtivreg2:
              webuse grunfeld
              xtivreg2 invest mvalue kstock, fe cluster(company)

              Comment


              • #8
                Thank you Martin, I am using stata intercool 13.

                Thanks Sergio and Eric for your quick response as well !

                Best,
                Rochelle

                Comment


                • #9
                  Hi!,

                  I am trying to run fixed effect with two-way clustering. For instance:
                  reghdfe capx x1 x2, absorb(firmid) vce(cluster firmid year) But after the regression output, it is showing that: vce(cluster firmid year) varlist not allowed r(101); I am using stata 16. Please give me some suggestions.

                  Comment

                  Working...
                  X