I have data in the following form
firm month_year sales competitor competitor_location competitor_branch_1 competitor_branch_2
1 1_2014 25 XYZ US EEE RRR
1 2_2014 21 XYZ US FFF
1 2_2014 21 ABC UK GGG
...
21 1_2009 11 LKS UK AAA
21 1_2009 11 AIS UK BBB
21 1_2009 11 AJS US CCC
21 2_2009 12 LKS UK AAA
I still want an entry for every firm at the month_year level but do not want separate rows for other variables, just columns. I am trying to turn it into this format.
firm month_year sales competitor_1 competitor_2 competitor_3 competitor_1_location competitor_2_location competitor_3_location competitor_1_branch_1 competitor_2_branch_1 competitor_3_branch_1 competitor_1_branch_2 competitor_2_branch_2 competitor_3_branch_2 competitor_1_branch_3 competitor_2_branch_3 competitor_3_branch_3
I thought reshape wide sales competitor competitor_location competitor_branch_1 competitor_branch_2, i(firm) j(month_year)
j
variable must be such that it uniquely identifies observations withinfirm
groups. Firm 21, for example, has several observations with the same date, so thereshape
won't work. Your example implies that you're trying to fill in one "cell" of the data matrix with more than one observation. Stata won't accept that. – Roberto Ferrerreshape
and you will see the difficulty. You've put no values in the desired format. The exercise is precisely about that. Simpler, you can do the exercise with the very small database found inhelp reshape
. – Roberto Ferrerreshape
with easier examples. What would you suggest for this case? – CJ12reshape
you say you want to do is impossible. You could make it so you have only one observation per firm (not firm date). But the layout of your data, and its usefulness, is something you have to determine according to the goal. I'll post an example with what I've mentioned. Usually, I'd go with data in long form, unless the estimation method forces me to go the other way. – Roberto Ferrer