[R] Error in lm() with very small (close to zero) regressor

RiGui raluca.gui at business.uzh.ch
Sat Mar 28 18:52:17 CET 2015

Thank you for your replies! 

I am terribly sorry for the code not being reproducible, is the first time I
am posting here, I run the code several times before I posted, but...I
forgot about the library used.

To answer to your questions:

How do you know this answer is "correct"? 

What I am doing is actually a "fixed effect" estimation. I apply a
projection matrix to the data, both dependent and independent variables,
projection which renders the regressors that do not vary, equal to basically
zero - the x1 from the post. 

Once I apply the projection, I need to run OLS to get the estimates, so x1
should be zero. 

Therefore, the results with the scaled regressor is not correct. 

Besides, I do not see why the bOLS is wrong, since is the formula of the OLS
estimator from any Econometrics book.

Here again the corrected code: 


n_obs <- 1000
y  <- rnorm(n_obs, 10,2.89)
x1 <- rnorm(n_obs, 0.00000000000001235657,0.000000000000000045)
x2 <- rnorm(n_obs, 10,3.21)
X  <- cbind(x1,x2)

 bFE <- lm(y ~ x1 + x2)

 bOLS <- pseudoinverse(t(X) %*% X) %*% t(X) %*% y


Raluca Gui 

View this message in context: http://r.789695.n4.nabble.com/Error-in-lm-with-very-small-close-to-zero-regressor-tp4705185p4705212.html
Sent from the R help mailing list archive at Nabble.com.

More information about the R-help mailing list