Dear all,
I'm currently working on a code for the estimation of clustered standard errors, which I'm trying to do using mata.
My code is similar to the one shared by David Drukker in the Statablog found here
The code that I'm trying to optimize is basically like the following:
It seems that this piece of code takes the longest time to produce what i want. (not terribly wrong, but much slower than say using "regress, cluster()"
Does anyone have any suggestions on making this code run faster?
Thank you in advance.
Fernando
Cross-posted in the general forum
I'm currently working on a code for the estimation of clustered standard errors, which I'm trying to do using mata.
My code is similar to the one shared by David Drukker in the Statablog found here
The code that I'm trying to optimize is basically like the following:
Code:
else if (vcetype == "cluster") { cvar = st_data(., clustervar, touse) info = panelsetup(cvar, 1) nc = rows(info) M = J(k, k, 0) dfr = nc - 1 for(i=1; i<=nc; i++) { xi = panelsubmatrix(X,i,info) ei = panelsubmatrix(e,i,info) M = M + (xi'*ei)*(ei'*xi) } V = ((n-1)/(n-k))*(nc/(nc-1))*XpXi*M*XpXi }
Does anyone have any suggestions on making this code run faster?
Thank you in advance.
Fernando
Cross-posted in the general forum
Comment