Hi,
I am using Stata 13 on Windows 10.
I have an unbalanced dynamic panel dataset of 90,000 firms operating in 50,000 markets (some in multiple markets, some in just one) across 13 years in which I want to use one firm per market as the benchmark for that market.
An example of the data for 3 firms in 2 markets over 3 years is as follows:
I want to be able to subtract the Production value of the benchmark firm from the other firms' Production in the corresponding market and year. My benchmark should be a firm that is active throughout the period. In the example above, firm 1 would be the benchmark in Market 1, and firm 2 the benchmark in Market 2. Therefore, I want to create an extra variable Benchmark as such
What I have at the moment is a variable to identify which firm should be my benchmark. I am missing the part where I create the Benchmark with the appropriate values.
What this code does is it puts the value of only one firm across these years for all markets. Like this:
Which is not what I want.
My goal is to then use xtabond2 to proceed to a DPD analysis. I want to define a benchmark for the variable Production, as well as for 3 other variables in the same way.
How would I generate such variable?
Thanks a lot for your help.
Cheers,
I am using Stata 13 on Windows 10.
I have an unbalanced dynamic panel dataset of 90,000 firms operating in 50,000 markets (some in multiple markets, some in just one) across 13 years in which I want to use one firm per market as the benchmark for that market.
An example of the data for 3 firms in 2 markets over 3 years is as follows:
id | Market | Year | Production |
1 | 1 | 1998 | 6.5 |
1 | 1 | 1999 | 7.3 |
1 | 1 | 2000 | 3.6 |
1 | 2 | 1999 | 4.8 |
1 | 2 | 2000 | 6.8 |
2 | 1 | 1998 | 1.2 |
2 | 1 | 1999 | 1.6 |
2 | 2 | 1998 | 4.4 |
2 | 2 | 1999 | 4.6 |
2 | 2 | 2000 | 5.8 |
3 | 1 | 2000 | 7.6 |
id | Market | Year | Production | Benchmark |
1 | 1 | 1998 | 6.5 | 6.5 |
1 | 1 | 1999 | 7.3 | 7.3 |
1 | 1 | 2000 | 3.6 | 3.6 |
1 | 2 | 1999 | 4.8 | 4.6 |
1 | 2 | 2000 | 6.8 | 5.8 |
2 | 1 | 1998 | 1.2 | 6.5 |
2 | 1 | 1999 | 1.6 | 7.3 |
2 | 2 | 1998 | 4.4 | 4.4 |
2 | 2 | 1999 | 4.6 | 4.6 |
2 | 2 | 2000 | 5.8 | 5.8 |
3 | 1 | 2000 | 7.6 | 3.6 |
Code:
/*Generate panel structure*/ egen panelid = group(id market), label xtset panelid year /*Create indicator for firm activity*/ egen prod_duration = count(production), by(panelid) gen negprod_duration = -prod_duration sort market year negdepo_duration panelid gen prod_benchmark = production if prod_duration == 3 sort year id negprod_duration /*Assign Benchmark production value to corresponding firm within market-year*/ bysort year (market negprod_benchmark panelid) : replace prod_benchmark = prod_benchmark[1] // This is what doesn't work
id | Market | Year | Production | Benchmark |
1 | 1 | 1998 | 6.5 | 6.5 |
1 | 1 | 1999 | 7.3 | 7.3 |
1 | 1 | 2000 | 3.6 | 3.6 |
1 | 2 | 1999 | 4.8 | 7.3 |
1 | 2 | 2000 | 6.8 | 3.6 |
2 | 1 | 1998 | 1.2 | 6.5 |
2 | 1 | 1999 | 1.6 | 7.3 |
2 | 2 | 1998 | 4.4 | 6.5 |
2 | 2 | 1999 | 4.6 | 7.3 |
2 | 2 | 2000 | 5.8 | 3.6 |
3 | 1 | 2000 | 7.6 | 3.6 |
My goal is to then use xtabond2 to proceed to a DPD analysis. I want to define a benchmark for the variable Production, as well as for 3 other variables in the same way.
How would I generate such variable?
Thanks a lot for your help.
Cheers,
Comment