Dear all,
I have a dataset with individual observations that are also classified by a time and a country variables. I have a dummy variable "shock", which takes value 1 for each individual for all those time observations in which the country has experienced an economic shock (in those cases, all the individuals in that given country have the dummy variable's value equal to 1). I am trying to generate a variable that computes the running sum of the shocks that happened "so far", but for each country - so that all the individuals will have a value equal to 0 as long as no shocks happened, equal to 1 once their country has experienced one shock, etc. I have tried with sum(), but it computes the running sum at the individual level and not distinguishing between countries.
Thank you for your help
Stefano
I have a dataset with individual observations that are also classified by a time and a country variables. I have a dummy variable "shock", which takes value 1 for each individual for all those time observations in which the country has experienced an economic shock (in those cases, all the individuals in that given country have the dummy variable's value equal to 1). I am trying to generate a variable that computes the running sum of the shocks that happened "so far", but for each country - so that all the individuals will have a value equal to 0 as long as no shocks happened, equal to 1 once their country has experienced one shock, etc. I have tried with sum(), but it computes the running sum at the individual level and not distinguishing between countries.
Thank you for your help
Stefano
Comment