I'm working with a panel data frame. I wanted to create a dummy variable that takes a value of 1 if the average value of the variable named "manu_GDP" is greater than or equal to 20 for each country in my dataset. I did this using the code below.
dummy <- df %>%
group_by(country) %>%
summarise(avg=mean(manu_GDP, na.rm=TRUE)) %>%
mutate(high_manu=ifelse(avg >= 20, 1, 0))
Now I want to create an alternative dummy variable that would take the value 1 if the value of manu_GDP (not its average over time) is greater than 20 in any given year for each country. For instance, the average value of manu_GDP could be less than 20 for Ethiopia but Ethiopia might have recorded a value of manu_GDP greater than 20 for a few years. I would like my alternative dummy variable to be able to pick this up.
Any advice on how I can do this?
Thanks very much in advance.
Aucun commentaire:
Enregistrer un commentaire