Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic Panel Data with multiple markets and a different benchmark firm per market

    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:
    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
    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
    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
    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.

    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
    What this code does is it puts the value of only one firm across these years for all markets. Like this:
    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
    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,
    Last edited by Louis Belisle; 07 Jun 2018, 12:38.

  • #2
    A potential solution I found:
    Code:
    egen numt_prod = sum(production>0 & production~= .), by(id market)
    sort market numt_prod
    gen tmp = 0
    replace tmp = 1 if market~=market[_n-1]
    egen longestdum = sum(tmp), by(id market)
    /*To populate benchmark's values in others*/
    egen production_base_mkt = sum(production*longestdum), by(market year)
    Another possible one
    Code:
    /*Create indicator for firm activity*/
    egen prod_duration = count(production), by(panelid)
    egen max_duration = max(prod_duration), by(panelid)
    gen tmp = production if prod_duration == max_duration gen
    rand = runiform()
    sort panelid year tmp rand
    replace tmp = . if !(_n == 1 | panelid[_n] != panelid[_n-1] | year[_n] != year[_n-1])
    egen prod_benchmark = max(tmp), by(panelid year)
    drop tmp rand

    Comment

    Working...
    X