Hi,
I am struggling to generate a loop which counts the number of values>0 across a set of 17 encoded string variables.
I have 17 variables (Bet1 - Bet17) and the data is in wide format. I want to generate a loop that counts the number of cells with a value>0 for each individual in the dataset (n=392), so that the count variable starts at 0 and adds one every time there is a cell>0 across the variables Bet1 to Bet17. It will calculate a total daily bets variable at the end.
Does anyone know where to start with this? My code so far looks like this:
local vars Bet1 Bet2 Bet3 Bet4 Bet5 Bet6 Bet7 Bet8 Bet9 Bet10 Bet11 Bet12 Bet13 Bet14 Bet15 Bet16 Bet17
gen followcount = 0
foreach v in local var {
replace followcount = followcount + 1 if "v">0
}
ta followcount
The error I am getting is related to the "v" being an invalid name - I have also tried i and x and neither of those work.
I am struggling to generate a loop which counts the number of values>0 across a set of 17 encoded string variables.
I have 17 variables (Bet1 - Bet17) and the data is in wide format. I want to generate a loop that counts the number of cells with a value>0 for each individual in the dataset (n=392), so that the count variable starts at 0 and adds one every time there is a cell>0 across the variables Bet1 to Bet17. It will calculate a total daily bets variable at the end.
Does anyone know where to start with this? My code so far looks like this:
local vars Bet1 Bet2 Bet3 Bet4 Bet5 Bet6 Bet7 Bet8 Bet9 Bet10 Bet11 Bet12 Bet13 Bet14 Bet15 Bet16 Bet17
gen followcount = 0
foreach v in local var {
replace followcount = followcount + 1 if "v">0
}
ta followcount
The error I am getting is related to the "v" being an invalid name - I have also tried i and x and neither of those work.
Comment