Announcement

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

  • xtreg vce(): too many variables error


    The xtreg manual says on p.7 for FE model (https://www.stata.com/manuals/xtxtreg.pdf)

    vce(cluster clustvarlist) specifies that standard errors allow for intragroup correlation within groups defined by one or more variables in clustvarlist, relaxing the usual requirement that the observations be independent. For example, vce(cluster clustvar1) produces cluster– robust standard errors that allow for observations that are independent across groups defined by clustvar1 but not necessarily independent within groups. You could also type vce(cluster clustvar1 clustvar2 . . . clusterp) to account for correlation within groups formed by p variables (multiway clustering).
    Given the last sentence, I tried the following,

    Code:
    use "http://www.stata-press.com/data/r14/nlswork.dta"
    xtset idcode year
    xtreg ln_wage age tenure, fe vce(cluster idcode year)
    Note that the last line has vce(cluster idcode year) where idcode corresponds to clustervar1 and year year to clustervar2 of the quote above. But, the code generates an error message

    Code:
    option cluster() incorrectly specified: too many variables specified
    What am I missing here?
    Last edited by Tetsu Haru; 29 Aug 2023, 00:35. Reason: f

  • #2
    Testsu:
    as far as I know the variable you cluster your standard errors on should be one only.
    If you want to cluster on more than one variable, you should switch to the community-contributed module -reghdfe- or, if feasible, create a new cluster variable via the -group- function available from -egen-..
    That said, in your case I would go:
    Code:
     
     use "http://www.stata-press.com/data/r14/nlswork.dta" xtset idcode year xtreg ln_wage age tenure i.year, fe vce(cluster idcode)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlo,
      Thanks for such a quick reply. As you suggested, i.year is missing in my code for two-way fe.

      If you are right on "the variable you cluster your standard errors on should be one only", then the last sentence of the quote above

      You could also type vce(cluster clustvar1 clustvar2 . . . clusterp) to account for correlation within groups formed by p variables (multiway clustering).
      is confusing for users like me. I wonder what the sentence means.....

      Thanks for your help any way.

      Comment


      • #4
        Tetsu:
        I do understand your point and obtained the very same error when clustering the standard errors (SEs) on more than one variable.
        Honesty, I did not delve into this issue, as I usually cluster the SEs on a single variable when going -xtreg,fe-.
        That said:
        1) clustering the SEs on a single variable is often enough;
        2) if your research goals call for something more elaborated, you can switch to the community-contributed module -reghdfe-.
        Last edited by Carlo Lazzaro; 29 Aug 2023, 01:22.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X