Announcement

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

  • Fillin by group

    Dear all,
    I made an earlier post and Clyde showed me how to do fill in http://www.statalist.org/forums/foru...ingle-variable

    My new request is to fill in by group, I did not find good information doing google search.

    Data have : if you read my last post (see link above), I added a new variable psic and a new observation 8700 , now I want to fill in sic for firms with the same psic, I call it psic cohort.

    gvkey if firm identifier

    Code:
    clear
    input int(gvkey psic sic) byte sale
    9375 100 100 100 
    8596 100 115 20 
    8596 100 6552 12 
    8596 100 7374 35 
    8700 3200 3200 56 
    end

    data want
    Code:
    clear
    input int(gvkey psic sic) byte sale
    9375 100 100 100 
    9375 . 115 . 
    9375 . 6552 . 
    9375 . 7374 . 
    8596 100 100 . 
    8596 100 115 20 
    8596 100 6552 12 
    8596 100 7374 35 
    8700 3200 3200 56 
    end
    so it fills in sic for firms sharing the same psic.

    Is there a by option for fillin?

    thanks,

    Rochelle

  • #2
    There is no by() option for fillin as a look at its help or indeed its code would confirm.

    But what I think you want is often asked here e.g.

    http://www.statalist.org/forums/foru...data-with-egen

    http://www.statalist.org/forums/foru...e-within-group
    Last edited by Nick Cox; 10 Jun 2016, 09:45.

    Comment


    • #3
      Thank you Nick for the links !

      My request seems to be slightly different from theirs. They need to fill in missing with a single value that exists in the group. My data needs to fill in multiple values within each group.

      e.g. for gvkey=9375, output data must add 2 new observations with sic = 115, 6552 because for the cohort psic=3100, it has 3 distinct sic 100, 115, 6552.

      for gvkey=8596, output data must add 1 new observation with sic = 100 because this firm currently has 2 records sic=115, sic=6552.


      for gvkey=8597, it is a cohort byitself, because no other gvkey share the same psic with this one. so no new rows added.

      see post #1 for data want.

      Comment

      Working...
      X