I have a dataset containing the daily rate of return for every industry (in total 10 industries) per country (in total 16 countries) from 1975 to 2018. Now I need to run cross sectional regressions per day and per week and save the coefficients in a separate dataset.
I tried the following code. But the estimates are the same for every day.
fitted_models = Data %>% 
                group_by(Data$Date) %>% 
                do(model = lm(Data$RoR ~ Data$Country + Data$Industry, data=Data))
fitted_models$model
I need to include the following contrasts:
contrasts(All0$Country) <- contr.sum(16, contrasts=TRUE)
contrasts(All0$Industry) <- contr.sum(10, contrasts=TRUE)
but I get the following error message then
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels In addition: Warning messages: 1: contrasts dropped from factor Country due to missing levels 2: contrasts dropped from factor Industry due to missing levels
This is a sample of my data. As time goes on there are values for RoR.
   Country        Date       Industry     RoR
   <chr>          <date>     <chr>      <dbl>
 1 Finland        1975-01-01 Basic Mats    NA
 2 Austria        1975-01-01 Basic Mats    NA
 3 Spain          1975-01-01 Basic Mats    NA
 4 United Kingdom 1975-01-01 Basic Mats    NA
 5 Norway         1975-01-01 Basic Mats    NA
 6 Germany        1975-01-01 Basic Mats    NA
 7 France         1975-01-01 Basic Mats    NA
 8 Italy          1975-01-01 Basic Mats    NA
 9 Portugal       1975-01-01 Basic Mats    NA
10 Switzerland    1975-01-01 Basic Mats    NA 
 
    