Statalist


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

Re: st: foreach loop over a column


From   Kushan Thakkar <[email protected]>
To   [email protected]
Subject   Re: st: foreach loop over a column
Date   Tue, 13 Oct 2009 22:02:28 -0400

Thanks for the response Kit.

You are right, these are permno from CRSP.

However, I am not looping over them to create another value. What I
need to do is, create another file (one per permno) that contains date
and the rolling volatility (something that I compute) for the 15 day
period.

And since I will need a separate file for every permno, I figure
looping over permno will be the best way.

What do you think?

On Tue, Oct 13, 2009 at 8:22 PM, Kit Baum <[email protected]> wrote:
> <>
> Kushan said
>
> I have a column name permno in my dataset. It is a numerical column,
> and I want to loop over it. This is what I did:
>
> foreach num in permno {
>       // do something
> }
>
> Martin explained why it didn't work, and suggested using -levelsof-. But
> under the assumption these are company permnos from CRSP, for instance, each
> observation has a unique value; they're just not consecutive integers.
>
> If you want to do something to every observation, realize that Stata is not
> SAS. Any expression you give in a -generate- (or -replace-) statement will
> automatically apply to each observation. If you have a variable totassets,
> for instance,
>
> gen lta = log (totassets)
>
> will create the value log total assets for every observation. There is no
> need to loop over observations, and in many cases, it is a bad idea to do
> so. The principle is that commands operate on the whole current dataset
> unless modified by -in range- or -if exp-.
>
> Kit Baum   |   Boston College Economics & DIW Berlin   |
> http://ideas.repec.org/e/pba1.html
>                              An Introduction to Stata Programming  |
> http://www.stata-press.com/books/isp.html
>   An Introduction to Modern Econometrics Using Stata  |
> http://www.stata-press.com/books/imeus.html
>
> *
> *   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/
>

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index