Reputation: 23
I am trying to create a new variable that counts the number of temperature variables whose value falls within a certain range of the temperature.
For example, my data looks like this -
I would like to create a new variable that counts the number of days where the temperature was within 30°C - 31.9°C. I tried to use egen
- anycount()
in Stata but it won't accept non-integers in the numlist.
Upvotes: 0
Views: 1601
Reputation: 1348
You can loop over the variables:
local vars T* // since your variables are named with this convention
generate count = 0
foreach v of local vars {
replace count = count + 1 if inrange(`v', 30, 31.9)
}
Upvotes: 2