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


From   Sadia Khalid <[email protected]>
To   [email protected]
Subject   st: Panel data - Foreach-Collapse commands
Date   Wed, 15 Jan 2014 01:18:53 +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



Here I am facing a number of issue/problems



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   invest kstock {

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

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

collapse `var' , by(company)



}



Getting the following error message.



“variable kstock not found”



1)      How I can over come this.



Secondly I want to get the following  table



                        Full sample
1935-45                                   1946-54

Full sample                              1984-1995
          1996-2005                   2005-2009

All Countries   aveage rolling SD  of Y                     aveage
rolling SD  of Y                      aveage rolling SD  of Y
       aveage rolling SD  of Y

Asian               aveage rolling SD  of Y
aveage rolling SD  of Y                      aveage rolling SD  of Y
              aveage rolling SD  of Y

                        (for Europe & Central Asia countries only)
(for Europe & Central Asia countries only)    (for Europe & Central
Asia countries only)           (for Europe & Central Asia countries
only)



African            aveage rolling SD  of Y          aveage rolling SD
of Y          aveage rolling SD  of Y                      aveage
rolling SD  of Y

                        (for Sub-Saharan Africa countries only)
 (for Sub-Saharan Africa countries only)         (for Sub-Saharan
Africa countries only)    (for Sub-Saharan Africa countries only)





How I can do this. I have generate this variable for number of variables.







3)



Rolling SD of X is calculated for each country. and average of rolling
SD of X is taken for each country and this is ploted against average
of SD of Y to have a scatter diagram.



Average of SD of Y on y-axis and SD of X on x-axis to get a scatter
diagram for countries according to there income group i-e all counties
, high income countries , low income countries.



How this graph can be drawn



Link of the data file is

https://www.dropbox.com/s/29a31q104iw6an4/panel.xlsx



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