Announcement

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

  • Overlapping markets

    Hi,
    I am using Stata 12.1/SE on a windows PC.

    I have a question regarding overlapping markets. Each firm and all its competitors within 2 miles are considered as one market.

    The data looks like this.

    firm1(i.e. market center) firm2 (i.e.competitor_within_2miles) price_difference
    A B 1
    A C 3
    A D 2
    A E 4
    B A 1
    B C 1
    B E 5
    B Z 2
    C A 3
    C B 1
    C X 9
    C Y 7

    Since firm pairs are not independent, I want to consider just non-overlapping markets.

    Therefore I need to drop some markets.

    Since I consider firms within 2 miles, my idea was drop all other markets within 4 miles, so that there cannot be any overlapping markets, because the rardii don't overlap.

    I just don't know how to tell Stata to do that and how to randomize this process, so that dropping markets is not biased.

    Any ideas?

    Best
    Christoph


  • #2
    Here's an outline of how I might approach this problem, a different approach than yours. I'm not sure this is actually doable, but perhaps by thinking about the problem from this angle it will give you some ideas.

    1) Handle the randomization by assigning a random number to each market (i.e. same random number for each row with the same firm1), then sort by the random number. For testing, be sure to set seed so that your tests are reproducible because it's surely not going to work right the first time, and you don't want to fix a problem only to have the fix go untested because of different randomization.

    2) For each market the sorted data, check firm1 against firm2 in all of the markets earlier in the file (all the markets with a smaller random number). If there's a match, then drop the rows for the market being examined. Similarly, for each row in the current market, check firm2 against both firm1 and firm2 in all of the markets earlier in the file, and if there's a match, drop the rows for the marketing being examined.

    You'll be left, I hope, with a set of markets such that any firm appears in at most one market.

    I'm sorry I don't have time at the moment to write and test this procedure, it sounds like a fun thing to try to implement in Stata. Although I'm not entirely convinced that my outline is actually implementable.

    Comment


    • #3
      It seems to me that a market overlap can be detected by noting that a firm appears in more than one market. So if you want to reduce your data to non-overlapping markets, all you need to do is to discard markets with firms that appear in more than one market. Something like:

      Code:
      clear
      input str1 (firm1 firm2) price_difference
      A B 1
      A C 3
      A D 2
      A E 4
      B A 1
      B C 1
      B E 5
      B Z 2
      C A 3
      C B 1
      C X 9
      C Y 7
      F G 3
      F H 1
      F I 9
      F J 7
      end
      
      * create a market identifier
      bysort firm1 (firm2): gen market1 = _n == 1
      gen marketid = sum(market1)
      
      * add firm1 to the market
      expand 2 if market1
      bysort marketid (firm2): replace firm2 = firm1 if _n == 1
      
      * in how many markets does a firm appear
      bysort firm2: gen Nmarket = _N
      
      * a market overlaps another if a firm appears in another market
      bysort marketid (Nmarket): gen overlap = Nmarket[_N] > 1
      
      * drop the extra obs created to include the market center
      drop if firm1 == firm2
      list, sepby(marketid) noobs

      Comment


      • #4
        Thanks for the suggestions. I thought about something like William. However, I don't know how to implement this in Stata.
        Because it is kind of a dynamic setting. When I pick one market, I need to drop many others. Then, those do not overlap with others.
        It is like a stepwise deletion of markets until there are no overlapping markets.

        If I just drop all overlapping markets I have too few observations left.
        So I need to pick certain markets that do overlap but then I need to delete the markets that overlap with them.

        So there may be 36 overlapping markets. However, I want to keep one of them and delete 35. But this in turn affects all other overlapping markets. With each market I drop the number of overlaps decreases....

        Any ideas how to implement that in Stata?

        Comment


        • #5
          Well if you created a market for each firm in the data, then my suggestion in #3 will simply wipe away all markets. Here's one suggestion on how to thin out markets by removing, at each pass, the market with the most overlap.

          Code:
          clear
          set seed 12346
          
          * Create 5 urban areas
          set obs 5
          gen uid = _n
          gen double ulat = 37 + (41 - 37) * runiform()
          gen double ulon = -109 + (109 - 102) * runiform()
          
          * Create firms centered on each urban areas
          expand _n * 100
          gen firmid = _n
          sort uid
          by uid: gen double flat = ulat + runiform() * .2 + runiform() * -.2
          by uid: gen double flon = ulon + runiform() * .26 + runiform() * -.26
          
          * Create 100 rural firms
          set obs `=_N+100'
          replace firmid = _n if mi(firmid)
          replace flat = 37 + (41 - 37) * runiform() if mi(ulat)
          replace flon = -109 + (109 - 102) * runiform() if mi(ulon)
          
          * Show a map of all firms
          scatter ulat ulon || scatter flat flon, msymbol(point)
          
          * create markets centered on firms (all) and find competitors (-geonear- is from SSC)
          tempfile firms
          save "`firms'"
          rename (firmid flat flon) (market mlat mlon)
          geonear market mlat mlon using "`firms'", n(firmid flat flon) long within(2) mi
          
          * delete markets with the most overlap
          local more 1
          while `more' {
              bysort firmid: gen Nmarket = _N
              bysort market: egen overlap = total(Nmarket)
              by market: gen candidate = overlap > _N
              sum overlap if candidate
              drop if candidate & overlap == r(max)
              count if Nmarket > 1
              local more = r(N)
              drop Nmarket overlap candidate
          }
          
          * Count the remaining number of markets and how many firms in each
          by market: gen marketN = _N
          by market: gen market1 = _n == 1
          tab marketN market1
          
          * Plot the firms in the remaining markets (and the original urban centers)
          merge 1:1 firmid using "`firms'", keep(match) nogen
          scatter ulat ulon || scatter flat flon, msymbol(point)

          Comment


          • #6
            Thanks so much. Yesterday I tried something similar.
            Maybe not that nice, but it also worked

            Comment

            Working...
            X