Hi,
I'm fairly new to Stata and am having difficulty with a bit of code that would be straightforward in other languages I'm familiar with.
As the topic title says, I want to count observations that satisfy a criteria, then using the resulting number in an 'if' statement. The pseudocode would look something like this (assuming 'treated' is a binary 1/0 variable):
gen treated_count = count(treated) if treated = 1
if treated_count < 1 do something
if treated_count == 1 do something else
if treated_count > 1 do something else
Thanks in advance for any help!
Jack
I'm fairly new to Stata and am having difficulty with a bit of code that would be straightforward in other languages I'm familiar with.
As the topic title says, I want to count observations that satisfy a criteria, then using the resulting number in an 'if' statement. The pseudocode would look something like this (assuming 'treated' is a binary 1/0 variable):
gen treated_count = count(treated) if treated = 1
if treated_count < 1 do something
if treated_count == 1 do something else
if treated_count > 1 do something else
Thanks in advance for any help!
Jack
Comment