My dataset is quite big so I'm just using 10 lines of data as an example (I've worked out the answer in excel but can't replicate it in R-as i need help with the code):
constant<-c(6.10,5.12,5.04,4.97,4.89,4.89,4.87,4.87,4.88,4.99)
years.star<-c(219.87,153.69,146.19,139.35,127.27,127.27,121.91,121.91,112.28,99.98)
years.sq.star<-c(7915.41,4610.71,4239.78,3901.93,3309.27,3309.27,3047.95,3047.95,2582.58,1999.62)
ln.salary<-c(28.43,23.12,21.59,21.44,22.71,23.33,20.29,21.76,21.48,22.92)
try<-data.frame(constant,years.star,years.sq.star,ln.salary)
Ln.salary is the dependant variable. The answer you should get is:
intercept- 6.474922
beta1- -0.15026
beta2- 0.002769
My problem is that in R, if I use the lm function, it does not know that my intercept has the values above. it just uses 1,1,1,1,1,1,1,1,1,1 instead of 6.10,5.12,etc
So test<-lm(ln.salary~years.star+years.sq.star,data=try,weights=constant)
does not work because it will just generate this answer:
intercept- 207.1706
beta1- -3.13214
beta2- 0.064416
In essence, I've taken data and tried to adjust for heteroscedasticity. In the final step, I have my constant star and my transformed x variables. The last step is to regress ln.salary on the constant and x variables to give me the answer you should get as per above.
I can do it in excel but not in R and I know I'm not getting the code right. I know the lm function which generates intercept (1,1,1...) is the problem. Please would you help.
Kind regards D