-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support for models with unit specific time trends? #24
Comments
Hi @TomBearpark, I think I'd have to change the data preprocessing to allow for that. I'll take a look at this tomorrow! |
I was about to suggest that you could try library(sandwich)
vcovBS(fit, cluster = ~Origin, type = "jackknife", center = "estimate") Unfortunately you also cannot use library(fwildclusterboot)
boottest(fit, param = ~dist_km, clustid = ~Origin, B = 9999, bootstrap_type = "31") So I'll take a closer look at this tomorrow! Best, Alex |
Thanks so much for your quick response Alex, and for looking into this! |
Hi @s3alfisc, I just wanted to follow up on this thread. Is there anything I could do to help? As far as I am aware, none of the existing packages provide support for estimating CV3 SEs with unit specific time trends. One practical solution I considered was to partial out the time trends prior to using your package. E.g., like this:
But I wasn't sure if there is some degrees of freedom correction, or other issue I am unaware of, that means this doesn't give the correct SEs. I'd be very grateful for any advice on this you may have! Thanks again, |
Hi @TomBearpark - I took another look and this and realized that it will not be possible for me to solve this. The reason is that the There are two things that you can do, demeaning prior to running Option 1: You implement the crv3 inference by hand. This can be done by simply looping over data sets for individual regressions. I implement such logic in pyfixest here. beta_jack = np.zeros((len(clustid), _k))
for ixg, g in enumerate(clustid):
# direct leave one cluster out implementation
data = _data[~np.equal(g, cluster_col)]
fit = feols(fml=self._fml, data=data, vcov="iid")
beta_jack[ixg, :] = fit.coef().to_numpy()
# optional: beta_bar in MNW (2022)
# center = "estimate"
# if center == 'estimate':
# beta_center = beta_hat
# else:
# beta_center = np.mean(beta_jack, axis = 0)
beta_center = _beta_hat
vcov = np.zeros((_k, _k))
for ixg, g in enumerate(clustid):
beta_centered = beta_jack[ixg, :] - beta_center
vcov += np.outer(beta_centered, beta_centered)
self._vcov += self._ssc[x] * vcov In a nutshell, for each cluster level g, you take the subset of data of cluster g. Then you fit the regression model on the subset. The other option is that you simply don't use fixest's library(broom)
fit = feols(log(Euros) ~ dist_km |Destination + Year + Destination[Year], df)
broom::tidy(fit, digits = 8)
fit = feols(log(Euros) ~ dist_km + as.factor(Destination):as.factor(Year) | Destination + Year, df)
broom::tidy(fit, digits = 8)[1:2, ] should give identical results. |
Just implemented an R function quickly that should not throw any errors: vcov3 = function(object, cluster){
data = fixest:::fetch_data(object)
cluster = data[,cluster]
unique_cluster = as.vector(unique(cluster))
G = length(unique(cluster))
fml_all = object$fml_all
obj_call = object$call
obj_call$data = quote(data[cluster == g,])
beta_centered = lapply(c(unique_cluster), function(g) coef(eval(obj_call)) - coef(object))
vcov = lapply(seq_along(unique_cluster), function(g) tcrossprod(as.matrix(beta_centered[[g]])))
vcov = Reduce("+", vcov) / G
vcov
}
#summary(fit)
vcov3(fit, "Year") # no error
sandwich::vcovBS(fit, cluster = ~Year, type = "jackknife", center = "estimate") fails You can use |
Thanks so much for your response! Your code is extremely helpful! With a few tweaks to your function, i think the version below seems to work well! The tweaks are:
Thanks again! |
Perfect! Glad that it works =) sorry about the few mistakes, it was approaching 23:00 here in Germany yesterday night and my brain wasn't at full capacity any more 😅 I think we should try to make this available more broadly. Maybe you could open an issue in the fixest repo and post the code there? Laurent has mentioned that he will have some guidelines on how to incorporate vcov types in a near release, and then you (in case you want to) or I could pick it up and make the function available from fixest? |
Thanks @s3alfisc ! I've posted the code into a fixest issue here. lrberge/fixest#481 |
Thank you! |
Hi, thanks for a great package!
I am trying to calculate CR3 standard errors for a model that includes unit specific time trends. Do you have any advice on how / if this can be implemented in summclust?
Here's a minimal example, showing the error that I get when I try to use the
summclust()
function on a model that includes unit specific time trends.The error is pasted below:
Thanks so much for your time and your help
The text was updated successfully, but these errors were encountered: