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]

Re: st: Foreach and collapse


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Foreach and collapse
Date   Wed, 15 Jan 2014 12:06:43 +0000

This crossed with my answer to a previous version of this question,
but regardless of that, just repeating a question and (what is more)
ignoring all previous answers to that question is a very bad idea. It
shows no sensitivity and is likely to mean that more and more people
just decide that you are expecting too much from the list.

Please do read the FAQ at

http://www.stata.com/support/faqs/resources/statalist-faq/

again and again until you understand this.
Nick
[email protected]


On 15 January 2014 11:58, Sadia Khalid <[email protected]> wrote:
> 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/

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