Multiplication of different FLAGs - fixed effects model

Viewed 22

I want to perform a regression in a fixed-effects model. To construct such a model, I have multiple FLAGs, like the following:

y ~ x + z + FlagYear1 + FlagYear2 + FlagYear3 + FlagCountry1 + FlagCountry2

I want to perform another regression in which I have fixed effects for Year * Country, so that the model will be equal to this

y ~ x + z + FlagYear1Country1 + FlagYear1Country2 + FlagYear2Country1 + FlagYear2Country2 + FlagYear3Country1 + FlagYear3Country2

As I have 26 countries and 8 Years in my model, so it would be very time-consuming to manually construct all the FLAGs. I know there is a command to perform this automatically in Stata, how can I do the same in R?

1 Answers

If by 'FLAG' you are referring to 0/1 coded indicator variables (or dummy variables) then R has an easy way to enter all of these interactions into a forumla.

If you have factor variables country with 26 levels and year with 8 levels then you can use

y ~ x + z + country*year

and this will expand the factors into every combination of country and year.

Look at the documentation for formula to understand how this works.

If you already have the indicator variables then you could use

y ~ x + z + (FlagYear1 + FlagYear2 + FlagYear3) * (FlagCountry1 + FlagCountry2)

Related