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
Calculate ratio by dateDear All, I'm trying to compute a ratio based on a date (def_date) in the dataset. I try to give a …
Accuracy of a new test using the diagti and sf(0) adjusted 95% CII have used the immediate command in STATA to calculate the accuracy and predictive values for a new…
Identifying and keeping the three highest-paid waitressesHi, I would like to identify the three highest-paid waitresses in terms of "total compensation" in e…
Using gsem with ordered categorical mediatorsHi, I want to run a mediation analysis looking at the direct and indirect effect of adolescent pers…
Cross sectional dependence/ xtpcseDear Members, I would like to know how do deal with cross sectional dependences. I have started doi…
Subscribe to:
Post Comments (Atom)
0 Response to Generating new columns for each unique value of a categorical variable
Post a Comment