Announcement

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

  • Adding an missing identifier when it is known in another year

    Hello,

    I have a database where the gvkey idenitfier is known for all firm year observations. But the cik identifier is not know for all firm year observations. For the table below the missing value should be 1750 based on the combination of gvkey and cik in other fiscal years. Is there a way that I could generate this missing value for all observations where it is missing but I know what it should be based on the gvkey-fyear combination in other rows?
    Thanks!


    cik gvkey fyear
    1750 1004 2015
    1750 1004 2016
    1750 1004 2017
    1750 1004 2018
    ? 1004 2019

  • #2
    I'm assuming this is panel data? Maybe this fixes your issue:

    Code:
    xtset gvkey fyear
    bys gvkey (cik): replace cik = cik[_N] if missing(cik)

    Comment


    • #3
      Yes, it is panel data. I tried your code, but it says "(0 real changes made)" after running.

      Comment


      • #4
        What does the "?" in your data set look like? Is it represented as missing (i.e. "." or an empty string)? You could post an example using -dataex-.

        Assuming cik is constant across gvkey and numeric you could also try

        Code:
        bys gvkey: egen cik2 = min(cik)
        replace cik = cik2
        drop cik2

        Comment


        • #5
          The question mark represents an "." in Stata. But I tried your second suggestion and that seems to solve my issue, so thank you very much for you help!

          Comment

          Working...
          X