Hi,
I am testing the DeclareDesign package and found a strange issue where the regression estimates 60 coefficients, but only produces 2 unique standard errors (which repeat over and over).
I am using the lm_robust function to compute the estimated means with clustered SEs for a panel dataset where counties are classified as either Democrat or Republican.
To ensure that this is not a strange idiosyncrasy of the data, I have produced a reproducible example below.
Any insight into this would be greatly appreciated!
Many thanks,
-at
Please see code for reproducible example:
#------------------------------------------------------|
#-------- Fabricate a panel with counties -----
#------------------------------------------------------|
# For each county,
# (a) we have a county-level fixed effect: county_FE
# (b) we have a classification as Democrat / Republican
#
# For each year,
# (c) we have a year-level random shock: year_shock
#
# For each county-year,
# (d) we have a measure of infrastructure spending:
# infrastructure.spend = county_FE + year_shock
#
#------------------------------------------------------|
require(magrittr)
require(dplyr)
require(tidyr)
require(stringr)
require(DeclareDesign)
panel <- fabricate(
county = add_level(N = 30, county_FE = runif(N, 1, 10)),
years = add_level(N = 30, year_shock = runif(N, 1, 10), nest=FALSE),
obs = cross_levels(by=join(county, years),
infrastructure.spend_it = county_FE + year_shock,
party = ifelse((as.numeric(county) %% 3) == 0,
"Democrat",
"Republican")) #split into 1/3 D and remaining 2/3 R
)
#---------------------------------------------------------------------------|
#-------- lm_robust: get means for party x year w. clustered SEs -----
#---------------------------------------------------------------------------|
#-------- create interaction term -----
panel %<>% mutate(year_by_party = interaction(years, party))
#-------- run robust lm with clustering on county id --------------------
lm_robust.out <- lm_robust(data = panel,
formula = infrastructure.spend_it ~ -1 + year_by_party,
clusters = county,
se_type = "CR2",
ci = TRUE,
alpha = 0.05)
#-------- tidy output to get table of means --------------------
lm_robust.out %<>% tidy()
lm_robust.out %<>%
mutate(term = str_remove(string = term, pattern = "year_by_party")) %>%
separate(term, into = c("year", "party"), extra = "merge", fill = "left") %>%
mutate(year = factor(year),
party = factor(party))
#------------------------------------------------------|
#-------- Examine Standard Errors -----
#------------------------------------------------------|
table(lm_robust.out$std.error) #only two values - one for each party type
View(lm_robust.out)