Hi there,
Here is an example for a dataset I am working with, which contains firm id, sector code, year and month only. Here I consider only 2 years and 3 months.
I want to:
1. expand this dataset
2. Create two variables treat1 and treat2 such that
treat 1 = 1 if a firm took a monthly action and is observed on that month. 0 otherwise
treat 2 = 1 if a firm has consecutively taken action at least two times within a year
Here is what I am looking for regarding the variables created
3. Next, I would like to create a variable time that goes from january2010 to march2011 such that
march2010 =0
feb2010=-1
jan2010=-2
jan2011=1
feb2011=2
march2011=3
Can anyone knows how to handle these tasks in Stata?
Here is an example for a dataset I am working with, which contains firm id, sector code, year and month only. Here I consider only 2 years and 3 months.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(firm_id1 sector) int year byte month 1 1 2010 1 1 1 2010 2 1 1 2010 3 1 1 2011 1 1 1 2011 2 1 1 2011 3 2 1 2010 1 2 1 2010 2 2 1 2010 3 2 1 2011 1 2 1 2011 2 2 1 2011 3 3 1 2010 1 3 1 2010 2 3 1 2010 3 end
I want to:
1. expand this dataset
2. Create two variables treat1 and treat2 such that
treat 1 = 1 if a firm took a monthly action and is observed on that month. 0 otherwise
treat 2 = 1 if a firm has consecutively taken action at least two times within a year
Here is what I am looking for regarding the variables created
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(firm_id1 sector) int year byte(month treat treat1 treat2) 1 1 2010 1 1 1 1 1 1 2010 2 1 1 1 1 1 2010 3 1 1 1 1 1 2011 1 1 1 1 1 1 2011 2 1 1 1 1 1 2011 3 1 1 1 2 1 2010 1 1 1 0 2 1 2010 2 1 1 0 2 1 2010 3 . 0 0 2 1 2011 1 1 1 0 2 1 2011 2 1 1 0 2 1 2011 3 . 0 0 3 1 2010 1 1 1 0 3 1 2010 2 . 0 0 3 1 2010 3 . 0 0 end
march2010 =0
feb2010=-1
jan2010=-2
jan2011=1
feb2011=2
march2011=3
Can anyone knows how to handle these tasks in Stata?

Comment