Displaying 1 result from an estimated 1 matches for "uniq_id".
Did you mean:
unique_id
2009 Feb 07
1
fixed effects regression
...ase.
I am pretty sure this would not have any fundamental error. Well, hopefully. I have been using this code for a while..)
And does anyone know how I can include another fixed effect into this code? :(
Any help will be deeply appreciated....
feols = function(y,X,id) {
n = length(y);
uniq_id = unique(id);
n_id = length(uniq_id);
dummy = matrix(rep(0,n*(n_id-1)),nrow=n);
for (i in 1:(n_id-1))
dummy[id==uniq_id[i],i] = 1;
X = cbind(rep(1,n),X,dummy);
k = ncol(X);
invXX = solve(t(X) %*% X);
b = as.numeric(invXX %*% (t(X) %*% y));
res = y - X%*%b...