Announcement

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

  • Import only observations that match values of a variable in current dta

    I have a dataset X with a variable "id". My goal is to import only the observations from dataset Y that share identical values for the 'id' variable found in dataset X. Note that I have no interesting in keeping X observations. How can I achieve this without merging both datasets and subsequently selecting data from Y? Dataset Y is too large to be imported whole.

  • #2
    Try this:
    Code:
    use id using dataset_X, clear
    duplicates drop
    merge 1:m id using dataset_Y, keep(match)
    I think that the -keep(match)- filter is applied while the merged file is being built. That is, I think Stata does not bring in the entire dataset_Y when you do it this way, but scans each observation to determine whether it is to be retained or not. If I'm wrong about that, post back to tell me that, and perhaps somebody else knows a better way and will respond.

    Comment

    Working...
    X