Statalist


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

Re: st: Build groups with the same first two numbers of SIC


From   "Hua Pan" <panhua@gmx.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Build groups with the same first two numbers of SIC
Date   Thu, 19 Mar 2009 20:50:59 +0100

Dear Nick, Michael and Martin

Thank you very much for your help. 

Michael, your command is great, very effective. That’s exactly what I want and failed to find. Thank you indeed.

Martin and Nick, Thank you for your suggestions. After I added “capture” before “by”, the loop continued to work, and I also got the daily mean return for all firms with this complicate method. After I typed, 
-di in red _rc-
the return code was 198. Does that mean that this code is wrong? Error (198)
When I put “capture” before “by” and “save”, the loop also continued to work and I got what I want, but this time the return code was zero. 
“Capture” is really useful, that can help me a lot later, so I want to know why there are different return codes and which one should I prefer? Thanks a lot in advance.

Best Wishes

Hua

-------- Original-Nachricht --------
> Datum: Thu, 19 Mar 2009 18:46:03 +0100
> Von: "Martin Weiss" <Martin.Weiss1@gmx.de>
> An: statalist@hsphsun2.harvard.edu
> Betreff: Re: st: Build groups with the same first two numbers of SIC

> <>
> 
> Other listers have highlighted easy fixes for your problem. Let me add: A
> failure of an -if- condition, as you describe in your post, need not kill a
> loop if you add -capture- in front of the respective command. If you want
> a record of the suppressed error, add the line
> 
> -di in red _rc-
> 
> afterwards to see whether the return code was non-zero.
> 
> 
> HTH
> Martin
> -------- Original-Nachricht --------
> > Datum: Thu, 19 Mar 2009 17:49:45 +0100
> > Von: "Hua Pan" <panhua@gmx.de>
> > An: statalist@hsphsun2.harvard.edu
> > Betreff: st: Build groups with the same first two numbers of SIC
> 
> > Dear Statalisters??
> > 
> > I have a list of firms with four digit sic code, permno (identify Nr.
> for
> > firms), date and return and wish to get daily mean return within the
> group,
> > which has the same first two numbers of SIC code.
> > 
> > My Dataset look like this:
> > 
> > sic     permno      date          ret 
> > …
> > 3674   10012    5.Jan.2004
> >         10012    6.Jan.2004
> >        10012    7.Jan.2004
> > 3674   10259    5.Jan.2004
> >        10259    6.Jan.2004
> >        10259    7.Jan.2004
> > 3674   10299    
> >        10299    
> >        10299  
> > 3674   10302
> >        10302
> >        10302
> > -----------------------------------------------------------------
> > 3714   10667
> >        10667
> >        10667
> > ------------------------------------------------------------------
> > 3728   10145
> >        10145
> >        10145
> > ------------------------------------------------------------------
> > 3861   10163
> >        10163
> >        10163
> > ------------------------------------------------------------------
> > 4213   10379
> >        10379
> >        10379
> > 4213   10649
> >        10649
> >        10649
> > 
> > 
> > At first I want to build several groups. Firms within each group have
> the
> > same character: the first two numbers of their SIC codes are identical.
> For
> > the example above   
> >         sic               permno
> > Group1: 3674              10012, 10259, 10299, 10302
> > Group2: 3714, 3728        10667, 10145
> > Group3: 3861              10163
> > Group4: 4213              10379, 10649
> > 
> > Then I wish to get mean daily return for each group.
> > 
> > So I just tried to separate the big dataset into several sub dataset,
> and
> > calculate daily mean return for each of them. Then I get the sub
> datasets
> > together with “append”. For the first step, I did: 
> > 
> > . local n=3600
> > . while `n' <4300 {
> >   2. use "D:\sic.dta", clear
> >   3. keep if sic >=`n' & sic < `n'+100
> >   4. by date, sort: egen meanret=mean(ret) 
> >   5. save "D:\ph\sic\sic_`n'.dta"
> >   6. local n=`n'+100
> >   7. }
> > 
> > 
> > It is successful for 36xx, 37xx. But when `n’== 3900, all observations
> > in the complete file “D:\sic.dta" are deleted, because none of them
> meet
> > the requirement: sic>=3900 & sic < 4000, so there is an error: 
> > 
> > (y observations deleted)
> > __000001 not found
> > 
> > y is the number of all the observations in complete dataset.
> > 
> > There are a huge number of observations, so I can’t do it one by one.
> > Has anyone here an idea to solve this problem? Or some easier methods to
> > generate such groups (I’ve also tried, but failed to get it ), so I
> can get
> > the daily mean return with:
> > 
> > by group date, sort: egen meanret=mean(ret)
> > 
> > Btw, I’m using stata 10.
> > 
> > 
> > Thank you very much for your help. 
> > 
> > Best Regards
> > 
> > Hua
> > 
> > 
> > -- 
> > Aufgepasst: Sind Ihre Daten beim Online-Banking auch optimal geschützt?
> > Jetzt absichern: https://homebanking.gmx.net/?mc=mail@footer.hb
> > *
> > *   For searches and help try:
> > *   http://www.stata.com/help.cgi?search
> > *   http://www.stata.com/support/statalist/faq
> > *   http://www.ats.ucla.edu/stat/stata/
> 
> -- 
> Martin Weiss
> Hackersteigle 3
> 72076 Tübingen
> 00497071/793535
> 00491784597218
> 
> Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen:
> http://www.gmx.net/de/go/multimessenger01
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/

-- 
Aufgepasst: Sind Ihre Daten beim Online-Banking auch optimal geschützt?
Jetzt absichern: https://homebanking.gmx.net/?mc=mail@footer.hb
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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