Announcement

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

  • Merge identifier and date within range

    Hi all,
    I would like to merge two datasets by identifier and date within range
    dataset A:
    accountnumber variableA date
    dataset B:
    accountnumber variableB startdate enddate

    I would like to have a dataset like:
    accountnumber variableA variableB date
    where date would be between startdate and enddate

    I looked at range join, but it seems like it would only accomplish merging using one variable? But I would like to have oaccountumber matched as well.

    Thanks so much!

  • #2
    But I would like to have oaccountumber matched as well.
    Is oaccountnumber a typo? You don't mention any such variable in either data set. But since you are concerned about "only accomplish merging using one variable" maybe you do have something else in mind? Anyway, to assure matches on accountnumber and date between startdate and enddate, you would use -rangejoin- as follows:
    Code:
    use dataset_B, clear
    rangejoin date startdate enddate using dataset_A, by(accountnumber)
    If there is, in fact, another variable that you want an exact match on, just add that variable name to the -by()- option. You can do exact matching on as many variables as you like. But only one variable can be matched on range.

    Comment


    • #3
      Yes it is a typo, thank yoU!

      Comment

      Working...
      X