0
$\begingroup$
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
relation <- lm(y~x) 
print(relation)
beta=solve(t(x)%*%x)%*%(t(x)%*%y)
print(beta)

Result from lm coeff = 0.6746

Result from beta econometrics = 0.4287

Why?

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to CV. Since you’re new here, you may want to take our tour, which has information for new users. Questions focusing on programming, debugging, or performing routine operations within a statistical computing platform are off-topic here. Still, what you are doing is basically estimating the same model without the intercept (see yourself lm(y~x -1)). Use model.matrix() function before solving the equation. $\endgroup$
    – T.E.G.
    Commented Aug 18, 2017 at 7:51

1 Answer 1

2
$\begingroup$

The results differ because you didn't include the intercept:

lm(y ~ 0 + x)
## 
## Call:
## lm(formula = y ~ 0 + x)
## 
## Coefficients:
##      x  
## 0.4287 

or

X <- cbind(Intercept = 1, x)
solve(t(X) %*% X) %*% (t(X) %*% y)
##                  [,1]
## Intercept -38.4550871
## x           0.6746104 

This has nothing to do with econometrics and I doubt any econometrics handbook or course recommends not including intercept as it is a bad practice.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.