I have a variable called color which records the fine-grained color of each observation. I would like to introduce a new variable called coarse-grained color that will have values that group together various specific colors within the same general color category e.g. different shades of green.
I am a beginner Stata user but based on a few posts I've read on this forum, I tried the following code:
Code:
generate coarse_grained_color = ""
local green_list `" "light green" "green, olive" "green - dark" "lime green" "'
* note I also tried removing the outer pair of double quotes since that seemed to be making this just one big string but that did not work either
foreach v of local green_list{
replace coarse_grained_color = "green" if fine_grained_color == "`v'"
}
I am trying to assign the variable coarse-grained_color the value green whenever it's fine-grained color is one of the values in the macro green_list. Please suggest a way that I can do this. When I tried my code, I don't get any errors but no changes seem to occur. In particular, the new variable coarse-grained color is still blank. thank you very much
0 Response to Looping over a list of phrases
Post a Comment