I have a (hopefully simple) question about using variable shortcuts and conditional statements. Suppose I have a series of similarly named variables (var_1-var_6), and they are all have some numerical value inside. Here is some quick reproducible example data:
Code:
*fake data clear input var_1 var_2 var_3 var_4 var_5 var_6 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 1 end gen country = "" replace country = "usa" in 1 replace country = "can" in 2 replace country = "sgp" in 3
Code:
mdesc var* if country=="usa"
For those interested (if it will help in providing a solution), the purpose of this question is to return a varlist of each var* that meets a certain level. Those vars that meet a certain level inform a process in a separate dataset. Each varlist is unique by country, such that the varslist considered for USA differs from CAN, SGP, etc.
Apologies if this question is poorly formatted - please let me know how I can improve it!
0 Response to Applying a conditional -if- statement to a set of variables without typing the names individually?
Post a Comment