Bookmark and Share

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


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

st: Foreach and collapse


From   Sadia Khalid <[email protected]>
To   [email protected]
Subject   st: Foreach and collapse
Date   Wed, 15 Jan 2014 16:58:34 +0500

I am working on panel data. I have to create the Rolling SD of Y variable.



Which I am able to create with the help of the  “ssc install mvsumm”



The command for creating the 3 year moving SD is



mvsumm y, stat(mean) win(3) gen(`var'3avg) end



the issue I am facing is that


As I have to do 3 year moving SD for number of variables.



So I am trying to use foreach command



This is the commands in do file



webuse grunfeld,clear

xtset company year

*** Code for calculating 3 Year moving SD**

global storelist ""

foreach var in   y x {

 global storelist = "${storelist} `var'"

mvsumm `var', stat(sd) win(3) gen(`var'3sd) end

collapse `var' , by(company)



}



Getting the following error message.



“variable x not found”

 link of the data file
https://www.dropbox.com/s/29a31q104iw6an4/panel.xlsx


How I can over come this.

Regards
Sadia Khalid

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index