Announcement

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

  • Merging

    Hi,

    I have the original Labour Force Survey dataset (LFS.dta) and a condensed version (final.dta) which I am working from with my own variables within it and many dropped variables. I forgot to include the ethnicity variable from the original LFS dataset in my condensed dataset, is there a command to just bring this over without having to re-drop all the variables? It is a variable with many observations.

    Thank you.

  • #2
    The -merge- command has a -keepusing()- option. You can specify the ethnicity variable in there and that is the only one that will be brought into your dataset.

    But what might be more efficient, if these files are large is to do something else. For illustration purposes I'll assume that a variable called unique_id uniquely identifies observations in both your working data set and the original LFS.dta. In reality, you will have to replace references to that below with the variable(s) that actually do that and can serve as a merge key.
    Code:
    use unique_id ethnicity using LFS, clear
    merge 1:1 unique_id using final, keep(match using)
    drop _merge // OPTIONAL, YOU  MIGHT WANT TO KEEP THIS
    Last edited by Clyde Schechter; 08 Mar 2024, 13:16.

    Comment

    Working...
    X