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
Using drop-command for a variable depending on the value of another variableHi, for my cumulative dataset (European Social Survey 2002-2018) I have a variable which measures if…
Panel data for for asset pricing modelsHi, Im working on my masters thesis. I have unbalanced panel data, for about 1550 individial mutual …
Monte Carlo simulation comparing output for OLS and 2SLS by saving beta and se's in matrixHi
In my simulation I am trying to compare output from OLS and 2SLS. I have the following code which…
xtlogit or pooled logit with repeated cross sectionsDear all,
I read a lot of the posts here about this topic but I got confused about something. So I w…
Instead of IV, can I simply run an OLS with the compliers?Imagine that I have a dummy variable that is a proper instrument. It identifies which observations o…
Subscribe to:
Post Comments (Atom)
0 Response to Generating new columns for each unique value of a categorical variable
Post a Comment