Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

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


From   LI Mengjia <limengjia626@163.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: How to use "by" or "if" in fill command
Date   Sun, 28 Apr 2013 05:14:11 +0800

Many thanks, Nick. Problem solved! Merge successfully finished!

Mengjia
在 2013-4-27,下午11:28,Nick Cox <njcoxstata@gmail.com> 写道:

> Some technique in
> 
> clear
> set obs 36
> gen year = 2002 + sum(mod(_n - 7, 12) == 0)
> 
> Nick
> njcoxstata@gmail.com
> 
> On 27 April 2013 16:10, LI Mengjia <limengjia626@163.com> wrote:
> 
>> 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?
> 
> *
> *   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/



*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index