Announcement

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

  • How to fill the missing value of companies by a specific value for each firm?

    Dear Stata community,
    Greetings!!!
    I wish to fill the missing values in the variable "coo" for all the years of an individual firm with the value of CO1 if first1=1.

    Kindly advise. Thanks


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(gvkey fyear) float(coo CO1 first1)
    1004 1993  .         . 1
    1004 1994  .         . 0
    1004 1995  .         . 0
    1004 1996  .         1 0
    1004 1997  .         0 0
    1004 1998  .         0 0
    1004 1999  .         0 0
    1004 2000  .         0 0
    1004 2001  .       .25 0
    1004 2002  .  .3333333 0
    1004 2003  .        .5 0
    1004 2004  .      .625 0
    1004 2005  .  .8571429 0
    1004 2006  .  .8888889 0
    1004 2007  .  .9090909 0
    1013 1993  .         . 1
    1013 1994  .         . 0
    1013 1995  .         . 0
    1013 1996  .        .3 0
    1013 1997  .  .3636364 0
    1013 1998  .  .3636364 0
    1013 1999  .  .3333333 0
    1013 2000  .        .7 0
    1013 2001  .      .625 0
    1013 2002  .        .3 0
    1013 2003  .  .3636364 0
    1013 2004  .         0 0
    1013 2005  .  .3076923 0
    1013 2006  .  .3333333 0
    1013 2007  .        .4 0
    1013 2008  .        .4 0
    1034 1993  .         . 1
    1034 1994  .         . 0
    1034 1995  .         . 0
    1034 1996  .         . 0
    1034 1997  .         0 0
    1034 1998  . .22222222 0
    1034 1999  . .22222222 0
    1034 2000  . .11111111 0
    1034 2001  . .11111111 0
    1034 2002  .        .3 0
    1034 2003  .  .6666667 0
    1034 2004  .  .6666667 0
    1034 2005  .        .7 0
    1034 2006  .        .5 0
    1034 2007  .        .5 0
    1045 1993  .         . 1
    1045 1994  .         . 0
    1045 1995  .         . 0
    1045 1996  .        .7 0
    1045 1997  .        .7 0
    1045 1998  .       .75 0
    1045 1999  .  .0909091 0
    1045 2000  .        .2 0
    1045 2001  .        .3 0
    1045 2002  .  .4166667 0
    1045 2003  .         . 0
    1045 2004  .         . 0
    1045 2005  .         . 0
    1045 2006  .         . 0
    1045 2007  .         . 0
    1045 2008  .         . 0
    1055 1993  .         . 1
    1055 1994  .         . 0
    1055 1995  .         . 0
    1055 1996  .         . 0
    1056 1999  .         . 1
    1056 2000  .         . 0
    1056 2001  .         . 0
    1056 2002  .         . 0
    1056 2003  .         . 0
    1056 2004  .         . 0
    1056 2005  .         . 0
    1056 2006  .         . 0
    1072 2000 .5        .5 1
    1072 2001  .        .5 0
    1072 2002  .         . 0
    1072 2003  .         . 0
    1072 2004  .         . 0
    1072 2005  .         . 0
    1072 2006  .         . 0
    1072 2007  .         . 0
    1076 1998  .         . 1
    1076 1999  .         . 0
    1076 2000  .         . 0
    1076 2001  .         . 0
    1076 2002  .         . 0
    1076 2003  .         . 0
    1076 2004  .         . 0
    1076 2005  .         . 0
    1076 2006  .         . 0
    1076 2007  .         . 0
    1078 1993  .         . 1
    1078 1994  .         . 0
    1078 1995  .         . 0
    1078 1996  .  .1818182 0
    1078 1997  .        .2 0
    1078 1998  .     .4375 0
    1078 1999  . .07692308 0
    1078 2000  . .08333334 0
    end
















  • #2
    If you mean fill all years if any year has first1=1, then

    Code:
    bys gvkey: egen tag= max(first1)
    replace coo= CO1 if missing(coo) & tag

    Otherwise, if you mean fill just the years for which first1=1, then

    Code:
    replace coo= CO1 if missing(coo) & first1
    Last edited by Andrew Musau; 07 May 2022, 03:09.

    Comment


    • #3
      thank sir
      Last edited by Miral Ayan; 09 May 2022, 12:23.

      Comment


      • #4
        Code:
        bys gvkey (fyear): replace coo= CO1[1]

        Comment

        Working...
        X