I have a dataset which contain a lot of variable and I need to do linear regression by countries. I have 7 countries here.1
Now, I want to use a loop to do regression separately. Here is my code:
lmcountry(witd_hw$countryest,witd_hw$AverageIncome,witd_hw$sqincome)
While, there seems to have a mistake: object of type 'closure' is not subsettable
but actually I can do the regression like:
lm(witd_hw$countryest~witd_hw$AverageIncome+witd_hw$sqincome,data=witd_hw[witd_hw$Country=="China",])