Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cluster specification in feglm formula has no effect? #17

Open
jay-sf opened this issue Oct 21, 2022 · 2 comments
Open

Cluster specification in feglm formula has no effect? #17

jay-sf opened this issue Oct 21, 2022 · 2 comments

Comments

@jay-sf
Copy link

jay-sf commented Oct 21, 2022

Hi,

first of all thanks for maintaining the alpaca package! I noticed the formula specification with FE and cluster to be very similar to lfe::felm which is very neat! I just recommended it on Stack Overflow.

However, I am not sure, if the cluster specification in the third part of the formula actually works and yields clustered standard errors as expected. We only seem to get those if we specify type="clustered", cluster=~i in the summary:

> set.seed(42); data <- simGLM(1000L, 20L, 1805L, model = "logit")

> summary(feglm(y ~ x1 + x2 + x3 | i + t, data), type="sandwich")$cm
    Estimate Std. error   z value Pr(> |z|)
x1  1.090884 0.02458502  44.37190         0
x2 -1.106484 0.02424425 -45.63902         0
x3  1.123164 0.02453891  45.77074         0
> summary(feglm(y ~ x1 + x2 + x3 | i + t | i, data), type="sandwich")$cm
    Estimate Std. error   z value Pr(> |z|)
x1  1.090884 0.02458502  44.37190         0
x2 -1.106484 0.02424425 -45.63902         0
x3  1.123164 0.02453891  45.77074         0
> summary(feglm(y ~ x1 + x2 + x3 | i + t, data), type="clustered", cluster=~i)$cm
    Estimate Std. error   z value Pr(> |z|)
x1  1.090884 0.02482350  43.94562         0
x2 -1.106484 0.02444224 -45.26933         0
x3  1.123164 0.02620042  42.86817         0
> summary(feglm(y ~ x1 + x2 + x3 | i + t | i, data), type="clustered", cluster=~i)$cm
    Estimate Std. error   z value Pr(> |z|)
x1  1.090884 0.02482350  43.94562         0
x2 -1.106484 0.02444224 -45.26933         0
x3  1.123164 0.02620042  42.86817         0

I noticed, a similar observation was made in an earlier issue.

It would be great if you could have a look at this.

Cheers!

@amrei-stammann
Copy link
Owner

amrei-stammann commented Nov 7, 2022

Hi,
alpaca only computes clustered standard errors if you specify type="clustered", cluster=~i. The third part in the formula only has to be specified if the cluster variable is not part of the model specification. Since i is already specified in the second part of the formula, you don't need to specify it again in the third part.

Best wishes,
Amrei

@pachadotdev
Copy link

hi @amrei-stammann
I made my own modification of Alpaca (Capybara), and one of the changes is to pass the cluster as y ~ a + b | fixedeffects | cluster
https://github.com/pachadotdev/capybara

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants