I often find myself writing a series of similar if statements, which in some other languages could be replaced by a switch-case statement. Here's an example of a switch-case statement in Python: https://jaxenter.com/implement-switc...on-138315.html
Is there anything like this in Stata? The closest thing I've found is a nested cond statement formatted onto separate lines, as described in Kantor & Cox (2005): https://journals.sagepub.com/doi/pdf...867X0500500310
Here's a series of if statements from some code I'm maintaining. It seems prolix, but maybe it's the best Stata can do?
Is there anything like this in Stata? The closest thing I've found is a nested cond statement formatted onto separate lines, as described in Kantor & Cox (2005): https://journals.sagepub.com/doi/pdf...867X0500500310
Here's a series of if statements from some code I'm maintaining. It seems prolix, but maybe it's the best Stata can do?
Code:
generate AgeMin = 0 replace AgeMin = 20 if AgeRange==1 replace AgeMin = 35 if AgeRange==2 replace AgeMin = 45 if AgeRange==3 replace AgeMin = 55 if AgeRange==4 replace AgeMin = 65 if AgeRange==5 replace AgeMin = 75 if AgeRange==6 generate AgeMax = 0 replace AgeMax = 34 if AgeRange==1 replace AgeMax = 44 if AgeRange==2 replace AgeMax = 54 if AgeRange==3 replace AgeMax = 64 if AgeRange==4 replace AgeMax = 74 if AgeRange==5 replace AgeMax = 76 if AgeRange==6
Comment