Reputation: 49
I want to create an if
statement in Stata based on the variable names. However, I couldn't find a way to create a local for variable names i.e. `variable_name_x'
foreach x of varlist dummyind_* {
hist x if `variable_name_x'==ind
}
clear
input float dummyind_1 float dummyind_2 str10 ind
0.1 0.7 dummyind_1
0.1 0.5 dummyind_2
0.2 0.8 dummyind_1
0.3 0.3 dummyind_2
0.4 0.2 dummyind_1
end
Upvotes: 0
Views: 266
Reputation: 37368
This is a fairly puzzling data structure, but I think I understand the question and guess you need something more like
foreach x of var dummy_ind* {
hist `x' if ind == "`x'"
}
That is, each variable name in question has two roles: (1) as a variable name (2) as a value of another string variable.
The above is using an if
qualifier, not an if
statement, which is different.
Upvotes: 2