Dear All,
Using STATA 13 I struggle with the following problem.
I want to construct a loop based on observations from one specific string variable (in my case retailer). Specifically, I need the following loop:
forvalue i in CO DL EV EV NW {
gen Sold_Product_`i' =.
Yet, I do not want the varlist (CO DL EV EV NW) to be fixed. I have this data in a variable but don't know how to transform it into a list. Also, some of the retailers are duplicates in my variable.
My data looks like this:
input str2(retailer) byte(product_id retailer_id)
"CO" 11 1
"CO" 6 1
"CO" 16 1
"DL" 9 2
"DL" 1 2
"DL" 17 2
"DL" 11 2
"DL" 4 2
"EV" 15 3
"EV" 7 3
"EV" 11 3
"NW" 13 4
"NW" 2 4
"NW" 17 4
"NW" 1 4
end
Many thanks in advance.
Best,
Markus
Using STATA 13 I struggle with the following problem.
I want to construct a loop based on observations from one specific string variable (in my case retailer). Specifically, I need the following loop:
forvalue i in CO DL EV EV NW {
gen Sold_Product_`i' =.
Yet, I do not want the varlist (CO DL EV EV NW) to be fixed. I have this data in a variable but don't know how to transform it into a list. Also, some of the retailers are duplicates in my variable.
My data looks like this:
input str2(retailer) byte(product_id retailer_id)
"CO" 11 1
"CO" 6 1
"CO" 16 1
"DL" 9 2
"DL" 1 2
"DL" 17 2
"DL" 11 2
"DL" 4 2
"EV" 15 3
"EV" 7 3
"EV" 11 3
"NW" 13 4
"NW" 2 4
"NW" 17 4
"NW" 1 4
end
Many thanks in advance.
Best,
Markus
Comment