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: Panel data - Foreach-Collapse commands


From   Sadia Khalid <[email protected]>
To   [email protected]
Subject   Re: st: Panel data - Foreach-Collapse commands
Date   Wed, 15 Jan 2014 08:14:47 +0500

Yes I want is
 collapsing on one variable , saving, reopening the original, collapsing...,

I have got the program to do but i cannot modify this to my situtation.

the link to the code is
http://www.urch.com/forums/phd-economics/125348-stata-repeated-collapse.html

yes i want to calculate the 3 Year  Moving Sd. like SD of (1,2,3)
first three obs and than SD of (2,3,4 )th obs ans so on.
 Regards
Sadia Khalid


On 15 January 2014 01:39, Nick Cox <[email protected]> wrote:
> Too many questions (at least for me to want to answer)!  I'll peel off
> the first.
>
> Once you -collapse- the first time round your loop, -kstock- has
> disappeared from your dataset. That's what -collapse- does: reduce
> your dataset to a new one. But the -collapse- is (arguably) illogical.
> Moving standard deviations are unique to each observation. A mean
> moving SD could be calculated, but it seems unlikely to be what you
> want. If it is really what you want, you need to read in the original
> data again.  On the other hand, I want whether you really want a
> moving SD. The rest of your question seems to imply otherwise.
>
> General comment: Some Statalist members use MS Excel. Many don't in
> practice or won't on principle.  It's not a good idea to imply that
> members are inclined to try and work out how to read your data into
> Stata from Excel.
>
> Nick
> [email protected]
>
> On 14 January 2014 20:18, Sadia Khalid [edited]
>
> 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 -mvsumm- (SSC).
>
> The command for creating the 3 year moving SD is
>
> mvsumm y, stat(mean) win(3) gen(`var'3avg) end
>
> As I have to do 3 year moving SD for a number of variables I am trying
> to use -foreach- and these are the commands in my do file
>
> webuse grunfeld,clear
> xtset company year
>  *** Code for calculating 3 Year moving SD**
>
> foreach var in   invest kstock {
>      mvsumm `var', stat(sd) win(3) gen(`var'3sd) end
>      collapse `var' , by(company)
> }
>
> I get the following error message.
>
>  “variable kstock not found”
>
> How can I overcome this?
>
> <big snip>
>
> *
> *   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