Dear Stata Users,
Please help me with the following issue.
I have a firm identifier (gvkey), year-month (fdate), shock (shock), production level (production) and identifier of a firm that experienced a shock (shock_firm). I need to study how the production was changing 10, 9, 8,… 1 months before the shock. Basically, I wanted to create a variable specifying the backward date, something like in the example below:
But the problem is that I have some firms that more than one shock year and they overlap. For instance:
I thought to introduce Back_date_1 and Back_date_2 for two different shock events (example below), but I have a maximum of 41 shock events that will complicate further use of these variables. Is there any other way I can create a back_date variable accounting for this circumstance?
Please help me with the following issue.
I have a firm identifier (gvkey), year-month (fdate), shock (shock), production level (production) and identifier of a firm that experienced a shock (shock_firm). I need to study how the production was changing 10, 9, 8,… 1 months before the shock. Basically, I wanted to create a variable specifying the backward date, something like in the example below:
Firm | Shock | Back_date |
A | 0 | -6 |
A | 0 | -5 |
A | 0 | -4 |
A | 0 | -3 |
A | 0 | -2 |
A | 0 | -1 |
A | 1 | 0 |
A | 0 | 1 |
A | 0 | 2 |
A | 0 | 3 |
A | 0 | 4 |
Firm | Shock | Back_date |
A | 0 | -6 |
A | 0 | -5 |
A | 0 | -4 |
A | 0 | -3 |
A | 0 | -2 |
A | 0 | -1 |
A | 1 | 0 |
A | 0 | 1 |
A | 1 | 2 |
A | 0 | 3 |
A | 0 | 4 |
Firm | Shock | Back_date_1 | Back_date_2 |
A | 0 | -6 | -8 |
A | 0 | -5 | -7 |
A | 0 | -4 | -6 |
A | 0 | -3 | -5 |
A | 0 | -2 | -4 |
A | 0 | -1 | -3 |
A | 1 | 0 | -2 |
A | 0 | 1 | -1 |
A | 1 | 2 | 0 |
A | 0 | 3 | 1 |
A | 0 | 4 | 2 |
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str24 gvkey float(fdate shock shock_firm production) "025279" 420 0 1 .3488717 "025279" 421 0 1 .2668857 "025279" 422 1 1 .1366463 "025279" 423 0 1 .028556867 "025279" 424 0 1 .8689333 "025279" 425 0 1 .3508549 "025279" 426 0 1 .07110509 "025279" 427 0 1 .32336795 "025279" 428 0 1 .5551032 "025279" 429 0 1 .875991 "025279" 430 0 1 .20470947 "025279" 431 1 1 .8927587 "025279" 432 0 1 .5844658 "025279" 433 0 1 .3697791 "025279" 434 1 1 .8506309 "025279" 435 0 1 .3913819 "025279" 436 0 1 .11966132 "025279" 437 1 1 .7542434 "025279" 438 0 1 .6950234 "025279" 439 0 1 .6866152 "102324" 423 0 1 .9319346 "102324" 424 0 1 .4548882 "102324" 425 0 1 .0674011 "102324" 426 0 1 .3379889 "102324" 427 0 1 .9748848 "102324" 428 0 1 .7264384 "102324" 429 0 1 .04541512 "102324" 430 0 1 .7459667 "102324" 431 1 1 .4961259 "102324" 432 0 1 .7167162 "102324" 433 0 1 .859742 end
Comment