Announcement

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

  • Help with merging and using specific years

    Hi all!

    Hoping a kind person can help a complete beginner, me, with the merge of two datasets when wanting to use data of different years in each set.

    The two datasets are "qog_std_ts_jan22" and "qog_ei_sept21". Both datasets have country level data with data for several years each.
    I have succesfully merged the two sets using "merge 1:1 cname year using qog_ei_sept21".
    However, when trying to drop the observations for the years I am not interested in, using "keep if _merge==1 & year ==2008" and "keep if _merge ==2 & year ==2005", the dataset gets completely wiped. However, i know that there are values for the years 2005 and 2008 respectively. Does the issue lie in merging the sets based on year, and if so, how would i work around this (only merging based on name does not work as each country has multiple observations.

    Thank you in advance for any help and apologies if this is very common knowledge, as mentioned I am completely new to Stata and statistical software in genaral.

  • #2
    keep has an implicit drop attached to it. If your data includes x and y, then keeping x drops y. So, you want to combine the commands or use drop which just drops what you specify.

    Code:
    keep if _merge==1 & year ==2008|_merge ==2 & year ==2005
    where the operator "|" refers to "or". See

    Code:
    help operators

    Comment


    • #3
      Thank you!

      Comment

      Working...
      X