Dear Stata Users,
I have the following dataexample:
----------------------- copy starting from the next line -----------------------
I would like to generate a variable: "gen_prof" for the profit of companies. The data should be like this:
----------------------- copy starting from the next line -----------------------
I mannually generated the variable "gen_prof".
When v_local = domestic, gen_prof = prof
when domestic = 12, I look at v_local = 12 and then gen_prof= prof when domestic = 12
when domestic = 13, gen_prof is missing because v_local doesnt have 13 at all.
This is repeated also for ID_com=2
I have an unbalanced data, so I think I cant just use the "merge", and was trying to figure out how to do this in stata. Please could someone give any ideas or help with this?
Best wishes
Max
I have the following dataexample:
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte(id_com v_local domestic) int porf 2005 1 11 11 1500 2005 1 11 12 1500 2005 1 11 13 1500 2005 1 11 14 1500 2005 1 12 11 2500 2005 1 12 12 2500 2005 1 12 13 2500 2005 1 12 14 2500 2005 1 14 11 1400 2005 1 14 12 1400 2005 1 14 13 1400 2005 2 11 12 554 2005 2 11 13 554 2005 2 11 14 554 2005 2 12 11 1690 2005 2 12 12 1690 2005 2 12 13 1690 2005 2 12 14 1690 2005 2 14 11 1400 end
----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year byte(id_com v_local domestic) int(porf gen_prof) 2005 1 11 11 1500 1500 2005 1 11 12 1500 2500 2005 1 11 13 1500 . 2005 1 11 14 1500 1400 2005 1 12 11 2500 1500 2005 1 12 12 2500 2500 2005 1 12 13 2500 . 2005 1 12 14 2500 1400 2005 1 14 11 1400 1500 2005 1 14 12 1400 2500 2005 1 14 13 1400 . 2005 2 11 12 554 1690 2005 2 11 13 554 . 2005 2 11 14 554 1400 2005 2 12 11 1690 554 2005 2 12 12 1690 1690 2005 2 12 13 1690 . 2005 2 12 14 1690 1400 2005 2 14 11 1400 554 end
I mannually generated the variable "gen_prof".
When v_local = domestic, gen_prof = prof
when domestic = 12, I look at v_local = 12 and then gen_prof= prof when domestic = 12
when domestic = 13, gen_prof is missing because v_local doesnt have 13 at all.
This is repeated also for ID_com=2
I have an unbalanced data, so I think I cant just use the "merge", and was trying to figure out how to do this in stata. Please could someone give any ideas or help with this?
Best wishes
Max
Comment