I have a matched employer-employee data set with 20 years of information on around 2.000.000 individuals and 400.000 firms. Amongst several worker- and firm-level covariates, I have worker, firm and occupation identifiers. My objective is to obtain 3 vectors of worker, firm and occupation fixed effects, estimated through a wage equation. I want to implement the Gauss-Seidel algorithm to obtain the exact least squares solution.
In a nutshell, I need to start with the three fixed effects' variables equal to zero, followed by estimation of the wage equation and update of each of the three coefficients sequentially until convergence is met, based on some convergence criterion (in this case, I'm following Guimaraes & Portugal 2010 by using a comparison between the residual sum of squares of the n-th and (n-1)-th estimations).
I've been trying to implement it on one of stata's default data sets (1978 automobile data) but without success. The problem I'm facing with the more tractable auto data, with only 1 fixed effect, is "invalid syntax". Here's the code for auto data:
Code:
sysuse auto keep if rep78 < . des gen double fe1 = 0 local rss1 = 0 local dif = 1 local i = 0 while abs(`dif')>epsdouble() { quietly { reg mpg weight gear_ratio fe1 predict double yhat local rss1=e(rss) local rss2=`rss1' local dif=`rss2'-`rss1' capture drop yhat gen double temp1 = mpg-yhat+_b[fe1]*fe1 capture drop fe1 egen double fe1=mean(temp1), by(rep78) capture drop temp1 local i=`i'+1 } } display "Total Number of Iterations --> " `i' quietly reg mpg weight gear_ratio fe1 estimates table, b(%10.7f)
Comment