Announcement

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

  • Generating a Fixed Effect for Pairs

    Hi All,

    I am dealing with FIPS code pairs. I would like to generate a fixed effect variable that matches the pairs. Please see an example below, that I would like my data to look like.
    FIPS FIPS2 County-Pair Fixed Effect
    1001 1021 1
    1021 1001 1
    1011 1005 2
    1005 1011 2
    1013 1035 3
    1007 1105 4
    1035 1013 3
    1105 1007 4
    1005 1067 5
    Thanks!

  • #2
    Code:
    egen country_pair = group(fips fips2)

    Comment


    • #3
      Thank you for your comment. I tried using the code above and unfortunately it does not recognize pairs across columns. Do you have a suggestion for generating a variable across the two columns? Cheers

      Comment


      • #4
        Oh, I see. You want 1001 1021 to be the same pair as 1021 1001. You even showed that in your example, but I didn't notice it. Sorry.

        Code:
        gen c1 = min(fips, fips2)
        gen c2 = max(fips, fips2)
        egen county_pair = group(c1 c2)
        
        list, noobs clean

        Comment


        • #5
          Hi Clyde,

          Thank you for your response! That worked!

          I also was able to generate a fixed effect using the code below, for anyone else who is interested in an alternative (yet more difficult) way of doing this:

          set more off
          levelsof FIPS1, local(F1)
          levelsof FIPS2, local(F2)

          gen count=0
          gen pair=.
          foreach f1 of local F1 {
          foreach f2 of local F2 {
          replace pair=count+1 if (FIPS1==`f1' & FIPS2==`f2') | (FIPS1==`f2' & FIPS2==`f1')
          replace count=count+1
          }
          }

          Comment

          Working...
          X