Announcement

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

  • Generate new variable without duplicates

    Hello
    I have one problem, I need to create a new variable:

    One extrait of my dataset is the following:
    id_observation: identification for each observation, there are duplicates
    year:
    country: 3 country
    total observation for each country without discriminate the year
    id_observation year country total observations
    1107 1996 A 71
    1101 1993 A 71
    1106 2003 A 71
    1105 2007 A 71
    1104 1987 A 71
    1103 1989 A 71
    1102 2007 A 71
    1101 1993 A 71
    2202 2013 B 114
    2201 1975 B 114
    2202 2013 B 114
    2203 2009 B 114
    2204 1993 B 114
    2206 2011 B 114
    2205 2014 B 114
    3304 2002 C 612
    3305 2009 C 612
    3303 1997 C 612
    3303 1997 C 612
    3301 2013 C 612
    3302 2007 C 612
    3308 1981 C 612
    3309 2004 C 612
    3303 1997 C 612
    3303 1997 C 612


    I have the total of observations for each country, according to each year I'd like to create one new variable which tells me how many unique observations are in each one, without duplicates

    Do you have any advices?

    Thank you so much for your help

  • #2
    You may think about using - duplicates tag - plus - generate() p for that matter.
    Best regards,

    Marcos

    Comment


    • #3
      Originally posted by Marcos Almeida View Post
      You may think about using - duplicates tag - plus - generate() p for that matter.
      I tried the first time:

      duplicates tag id_observation year, gen(tag)

      tab tag if country=="A"

      And the total is the total observations with duplicates

      For that reason, I don't know what to do

      Comment


      • #4
        If I understood right, with - tab tag - you’ll get the duplicates plus the unique values. The sum, logically, will be the total of observations. That being said, you may - keep - the unique values - or use the “if” clause to select your sample in each estimation. Hopefully that helps.
        Best regards,

        Marcos

        Comment


        • #5
          Thank you so much, it worked with if clause

          Comment


          • #6
            Thank you for informing your query reached a satisfactory reply.
            Best regards,

            Marcos

            Comment

            Working...
            X