Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Austin Nichols <austinnichols@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Question about fillin |
Date | Thu, 14 Feb 2013 10:40:21 -0500 |
André Gyllenram <a_gyllenram@hotmail.com> : This might do what you want. clear input indiv str1 s period 1 C 1 1 E 1 1 A 2 1 F 2 2 G 1 2 H 1 2 G 2 2 K 2 end encode s, g(stock) g t=period egen maxperiods=max(t), by(indiv) egen nperiods=count(t), by(indiv stock) g x=maxperiods-nperiods+1 bys indiv stock (t): replace x=1 if _n<_N expand x bys indiv stock (t): replace period=_n list, sepby(indiv) noo On Thu, Feb 14, 2013 at 9:16 AM, André Gyllenram <a_gyllenram@hotmail.com> wrote: > Hello, > > I have a question about the command fillin. > > It is not possible to combine this with by. But can you do in some other way? > > I would like to write like this: > > by individual: fillin individual stock period. > > > My data looks like this; > > INDIVIDUAL STOCK PERIOD > 1 C 1 > 1 E 1 > 1 A 2 > 1 F 2 > > 2 G 1 > 2 H 1 > 2 I 2 > 2 K 2 > > And I would like to add observations with missing data so that in every time period there is a row for all stocks that the individual owns in any period. Individual 1 owns > stock C, E, A and F in period 1 or 2. This means that i want a row for these stocks in every time period for individual 1. > > Individual 2 owns stock G, H, I an K in period 1 or 2. So for every time period I want a row for these stocks for individual 2. In this example I want to add observations so the data looks like this: > > > INDIVIDUAL STOCK PERIOD > 1 A 1 > 1 C 1 > 1 E 1 > 1 F 1 > 1 A 2 > 1 C 2 > 1 E 2 > 1 F 2 > > 2 G 1 > 2 H 1 > 2 I 1 > 2 K 1 > 2 G 2 > 2 H 2 > 2 I 2 > 2 K 2 > > So in this example I want to add 8 rows. If I write fillin individual period I would add much more rows than i want to since the individuals together own stocks A, C, E, F, G, H, I > and K. > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/