I've panel data on annual credit-to-GDP (c_gdp) ratio for 48 countries (countrycode) between 1980-2010 (year). I've generated a dummy variable (boom) that is '1' if the change in the credit-to-GDP ratio in the previous four years (including the current year) is positive - a 'credit boom'.
Given the nature of the data, this results in separated clusters of such booms where, for example, boom = 1 when year = 1987, 1988, 1989, 1990, and 1991 (5 consecutive years). The 'boom' variable is then a missing value until boom = 1 again when year = 2001 ... 2009 (9 consecutive years). I would like to count the number of 1's in these separate clusters (i.e., 5 for the first cluster, 9 for the second cluster, and so on) and am unable to figure out how to count separate clusters for each country within the same variable.
For your reference, here is an example using grunfeld, where I would like to count the separate clusters of 1's in the 'boom' variable for each company:
webuse grunfeld, clear
drop invest kstock time
tsset company year
gen D_mvalue = D.mvalue
gen boom = 1 if D_mvalue > 0 & !mi(D_mvalue)
Thank you for your consideration.
Given the nature of the data, this results in separated clusters of such booms where, for example, boom = 1 when year = 1987, 1988, 1989, 1990, and 1991 (5 consecutive years). The 'boom' variable is then a missing value until boom = 1 again when year = 2001 ... 2009 (9 consecutive years). I would like to count the number of 1's in these separate clusters (i.e., 5 for the first cluster, 9 for the second cluster, and so on) and am unable to figure out how to count separate clusters for each country within the same variable.
For your reference, here is an example using grunfeld, where I would like to count the separate clusters of 1's in the 'boom' variable for each company:
webuse grunfeld, clear
drop invest kstock time
tsset company year
gen D_mvalue = D.mvalue
gen boom = 1 if D_mvalue > 0 & !mi(D_mvalue)
Thank you for your consideration.
Comment