Announcement

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

  • Replace variable with subset of observations

    I haven't used Stata in a while now and am a bit ashamed that I don't know how to proceed with this fairly easy task.

    Data sample (I leave out other variables for illustrations purpose)

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input long Acq_Boardex_ID str12 Acq_Isin byte _merge
    26113 "AU000000RMD6" 1
    26113 "AU000000RMD6" 1
    26113 "AU000000RMD6" 1
    26113 "AU000000RMD6" 1
    26113 "AU000000RMD6" 1
    26113 "US7611521078" 3
    26113 "US7611521078" 3
    26113 "US7611521078" 3
    26113 "US7611521078" 3
    26113 "US7611521078" 3
    end
    label values _merge _merge
    label def _merge 1 "Master only (1)", modify
    label def _merge 3 "Matched (3)", modify
    Acq_Boardex_ID is a company ID. Acq_Isin should be the same for each company (Acq_Boardex_ID) in my sample.
    By Acq_Boardex_ID, I would like to replace the Acq_Isin in cases where _merge = 1 with the Acq_Isin from the company where _merge = 3.
    This is probably a super easy task but due to my rusty Stata knowledge, I haven't really got any further with a solution and appreciate any help.

    Best

  • #2
    There is no need to feel embarrassed by this question. The fact that the problem can be solved in one line really doesn't make it trivial because that one line does a great deal.
    Code:
     bysort Acq_Boardex_ID (_merge) : replace  Acq_Isin = Acq_Isin[_N] if _merge[_N] == 3

    Comment


    • #3
      Indeed, the line does a great deal.
      Thank you very much, Nick!

      Comment

      Working...
      X