Announcement

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

  • giving the same values to the same ID's variable

    Hello,

    I'm manipulating panel data and have a question regarding some variables. I have firms as the unit of analysis and each of them are given an ID. While information on their "entry of year" variable should be the same with the ID, some errors exist - e.g. some of the entry year is 1992 and others 1993 for the same firm - which I believe is a typo. I hope to align them all and make the information consistent within the ID. What command do I need to use? Or at least can I tag them to check?

    Thank you for your help in advance!



  • #2
    You can tag the id's where years are different like this (if your entry year variable is called 'year'):
    Code:
    bysort id (year): gen tag = year[1] != year[_N]
    list id year if tag
    The command for replacing differing years depends on how you want to replace years, i.e. do you want the minimum year, maximum year, first occurring year etc.

    Comment


    • #3
      Thank you so much, Wouter!!! How could I replace years to the minimum year?

      Comment


      • #4
        Code:
        bysort id (year): replace year = year[1]
        Although it is safer to generate a new variable:
        Code:
        bysort id (year): gen year1 = year[1]
        If it turns out that it wasn't a data entry mistake after all this can save you from having to import and manipulate the data again.

        Comment


        • #5
          Thank you so much!!!

          Comment


          • #6
            Hello Wouter (or anyone who can help),

            I'm very sorry to bother you again but could I ask you which command I need to use for maximum year? I asked about the minimum year last time... (e.g.
            bysort id (year): gen year1 = year[1]) Thank you for your help again!

            Comment


            • #7
              Code:
              bysort id (year): gen year1 = year[_N]
              except that if some values are missing you should use

              Code:
              bysort id: egen year1 = max(year)

              Comment


              • #8
                Thank you so much!!!

                Comment

                Working...
                X