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

Re: st: foreach loop over a column

From   Kit Baum <>
Subject   Re: st: foreach loop over a column
Date   Wed, 14 Oct 2009 08:21:17 -0400

I still don't think you want or need an explicit loop. I presume this is panel data from CRSP, sorted by permno and date. Generally what you are trying to do can be done with a by-prefix (see ISP below). For computing rolling measures in a panel, you can either use the rolling prefix (which will create one new file) or Baum-Cox -mvsumm-:

webuse grunfeld, clear
ssc inst mvsumm, replace
mvsumm invest, gen(rollvol) stat(sd) window(3) end
l company year invest rollvol if company<4

In no case should you need to create a separate file for each permno. Presuming you have hundreds of permnos, that is crazy. Keep the stuff all in one file (using either rolling: or mvsumm) and pick out what you need.

On Oct 14, 2009, at 2:33 AM, Kushan wrote:

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

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?

Kit Baum   |   Boston College Economics & DIW Berlin   |
An Introduction to Stata Programming |
   An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

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