Dear All,
The issue I am trying to resolve here is as follows-
I have a dataset where customers purchase products from multiple brands in a single order, identified by "Order_id". The variable "Brand", has 5 unique values, but in a single order it may be present once or more than once. I want to create new columns with the brand name, which indicates if it was present in a certain order (i.e. takes values of 1/0 in the new column). Please find below an example:
My existing data:
Order_id Brand
100 A
100 B
100 C
101 D
101 D
102 E
102 A
102 C
102 A
What I want to create is something like this:
Order_id Brand A B C D E
100 A 1
100 B 1
100 C 1
101 D 1
101 D 1
102 E 1
102 A 1
102 C 1
102 A 1
Please let me know if this explanation is clear, and if there is a way to do it in Stata?
Thanks!
Related Posts with Generating new columns for each unique value of a categorical variable
Obtain which bin and corresponding density each observation in plotted histogram belongs to?Hello everyone, Suppose I plot a histogram: Code: clear set obs 10 g z = _n replace z = 5 if _n …
spmap polygon sepearate graphsDear all, I'm trying to overlay EU NUTS2 and NUTS3 using spmap, but the polygon option doesn't combi…
Same date or within 7 days, within two variablesDear statalist-members, I need to identify patients that got med1 and med2 on the same day, or withi…
Checking DuplicationsI am trying to use xtset and I know how to remove any duplications. Is there a way to see if the non…
Simple percentiles using wide datasetHello, I'm not sure why I am having such trouble creating a variable corresponding to percentiles. …
Subscribe to:
Post Comments (Atom)
0 Response to Generating new columns for each unique value of a categorical variable
Post a Comment