Hi,
I want to generate a two-way graph for a difference in difference analysis. I have a dummy variable (d_MA) that measures whether or not a firm engaged in M&A. I have another dummy variable (SICMatch) that measures the relatedness of the two firms (I only have data for this variable for the M&A firms). . I want to create a graph with time on the x axis and patent output on the y axis that shows 5 lines: 4 for the different relatedness dummies, and 1 for the non-M&A group.
I tried to do this, however I need to have only 1 value per time variable in order to generate a clean graph. I think the collapse function could provide a solution. However I was not able to use it properly.
I used the following stata commands to do this:
This is the graph I get:

I want to generate a two-way graph for a difference in difference analysis. I have a dummy variable (d_MA) that measures whether or not a firm engaged in M&A. I have another dummy variable (SICMatch) that measures the relatedness of the two firms (I only have data for this variable for the M&A firms). . I want to create a graph with time on the x axis and patent output on the y axis that shows 5 lines: 4 for the different relatedness dummies, and 1 for the non-M&A group.
I tried to do this, however I need to have only 1 value per time variable in order to generate a clean graph. I think the collapse function could provide a solution. However I was not able to use it properly.
I used the following stata commands to do this:
Code:
egen Average_Patents_merged1 = mean(lnPatents) if d_MA==1 & SICMatch ==1, by(time) egen Average_Patents_merged2 = mean(lnPatents) if d_MA==1 & SICMatch ==2, by(time) egen Average_Patents_merged3 = mean(lnPatents) if d_MA==1 & SICMatch ==3, by(time) egen Average_Patents_merged4 = mean(lnPatents) if d_MA==1 & SICMatch ==4, by(time) egen Average_Patents_Notmerged = mean(lnPatents) if d_MA==0, by(time) graph twoway (line Average_Patents_merged1 time if d_MA==1) (line Average_Patents_merged2 time if d_MA==1) (line Average_Patents_merged3 time if d_MA==1) (line Average_Patents_merged4 time if d_MA==1)(line Average_Patents_Notmerged time if d_MA==0), xtitle("Time") ytitle("Patent output") xlabel(-3 (1)3) xline(0)
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(lnPatents d_MA) byte(time SICMatch) 6.383507 0 1 0 6.487684 0 -3 0 6.725034 0 -1 0 8.02027 1 -2 4 7.608871 1 3 4 7.860185 1 1 4 4.317488 0 -1 0 4.859812 0 2 0 4.406719 0 -3 0 4.59512 0 1 0 4.7361984 0 3 0 4.7361984 0 0 0 4.26268 0 -2 0 2.3025851 0 -2 0 2.890372 0 3 0 2.944439 0 2 0 2.995732 0 -3 0 2.833213 0 -1 0 3.178054 0 1 0 3.3322046 0 0 0 2.0794415 1 -2 0 2.995732 1 2 0 2.833213 1 0 0 2.397895 1 1 0 2.995732 1 3 0 2.1972246 1 -1 0 1.7917595 0 1 0 2.397895 0 0 0 .6931472 0 1 0 1.94591 0 3 0 1.0986123 0 -3 0 2.1972246 0 -2 0 1.94591 0 -1 0 5.09375 0 3 0 5.129899 0 -1 0 end
This is the graph I get:
Comment