Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: How to use "by" or "if" in fill command

From   LI Mengjia <>
Subject   st: How to use "by" or "if" in fill command
Date   Sat, 27 Apr 2013 23:10:30 +0800

Dear statalists,

I want to generate a sequence with certain repeated pattern as part of a match-erge procedure to merge the stocks in fund holding (reported every half year) with stock return data (reported every month) in order to display stock's monthly return in the fund holding file.

My current data structure looks like this: (each fund has several stocks, each stock have 36 rows at each Reportyear)

fund                   stock         Reportyear     year 
000011.OF       000001         2005
(repeated for 36 rows for each stock code)
000011.OF       000002         2005
000021.OF                           2005 
000011.OF                           2006 
...                                          2010

I want to fill column year in patterns like (first year 2002 repeats 6 times, middle 2 years 2003 & 2004 repeat 12 times and last year 2005 repeat for 6 times):
For each stock when Reportyear=2005, year= 2002,2002,2002,2002,2002,2002,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2005,2005,2005,2005,2005,2005,(in vertical)
And when Reportyear increase by 1, year increase by 1.

I read the FAQ article "Generating variables that contain repeating sequences of numbers". I think "egen fill" will satisfy part of my need since each value in the repeating sequence is repeating different times. But "by" and "if" is not allowed for egen fill.How should I generate the year pattern for each Reporttime?

Thanks and looking forward to your reply,

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index