Announcement

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

  • Drop observations in variable

    Hello : )

    I have a question about deleting observations in a variable.

    My unit of analysis is country-year and in my "country"-variable, I have over 20,000 observations, with countries I don't need for my analysis. Same goes with the "year" variable. How can I drop/ delete particular observations (=countries/ years) from those variables? I have more than 150 countries included in the variable, but I need probably around 50 - so there are a lot of countries I need to delete.

    How to I do that?

    Every help is very much appreciated, thank you!

    Kind regards,
    M.

  • #2
    drop is the key word.

    Code:
    drop if inrange(year, 1, 1800)
    is an example. See

    Code:
    help drop

    If you have a list of countries you wish to drop, it may be easiest -- rather than writing a long command or a series of commands -- to put those in a separate dataset, merge and then drop the intersection of the datasets. For the flavour see https://www.stata.com/support/faqs/d...s-for-subsets/

    Comment


    • #3
      Hey Nick,
      thank you very much for your reply!

      I assumed you mean with "inrange" that every observation between 1 and 1800 was deleted, correct?

      So I tried it for country (e.g. the country afghanistan (listed as first) from column 1-77), but that didn't work. Stata's response was: "type mismatch"...

      Comment


      • #4
        No; inrange(year, 1, 1800) means year >= 1 & year <= 1800 which was deliberately a facetious example for what I imagine to be your data.

        If country is a string variable you need if country == "Afghanistan" or something similar.

        Otherwise if this remains unclear, you may need to give us a data example as explained in the FAQ.

        Comment


        • #5
          You are correct - "country" is a string variable in my dataset. I typed "drop if country == "afghanistan"" and it worked. Thank you very much for your help!

          Comment

          Working...
          X