Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: AW: Tssmooth Ma Missing Values


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: Tssmooth Ma Missing Values
Date   Thu, 25 Mar 2010 14:57:15 +0100

<> 

You can change the values after the fact:


*************
clear*

input str10 Country	 Year	byte Variable	 
Australia	 1897	 .	
Australia	 1898	 .	
Australia	 1899	 .	
Australia	 1900	 .	
Australia	 1901	 0	
Australia	 1902	 1	
Australia	 1903	 2	
Australia	 1904	 3	
Australia	 1905	 4	
Australia	 1906	 5	
Australia	 1907	 6	
Australia	 1908	 7	
Australia	 1909	 8	
Australia	 1910	 9	
Australia	 1911	 10	
Australia	 1912	 .	
end

tsset Year, yearly

tssmooth ma twoyearMA=Variable, window(0 1 1)
tssmooth ma fiveyearMA=Variable, window(0 1 4)
tssmooth ma back2yearMA=Variable, window(1 1 0)

foreach var of varlist *yearMA{
	replace `var'=. if mi(Variable)
}

list, noo
*************


BTW, did you really tell Stata to create variables named "5yearMA" and the
like? Those names are illegal, and would be rejected.


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von
J.M.Chwieroth@lse.ac.uk
Gesendet: Donnerstag, 25. März 2010 11:55
An: statalist@hsphsun2.harvard.edu
Betreff: st: Tssmooth Ma Missing Values

I'm trying to generate 2 and 5 year forward and backward moving averages for
a particular variable.   A sample of the data structure appears below.  To
generate the moving averages below I have used the following syntax:
 
tssmooth ma 2yearMA=Variable, window(0 1 1)

tssmooth ma 5yearMA=Variable, window(0 1 4)

tssmooth ma Back2YearMa=Variable, window(1 1 0)

 

The problem I encounter is that the forward moving average syntax leads
Stata to create new values prior to the start of the times in rows where I
am missing data for the variable.  At the end of the time series the same
occurs for the backward moving average.  Ideally, I want Stata to produce
moving averages only in years for which I have data for the variable.  

Is there some syntax I could use to tell Stata not to create these new
values in rows where I have missing data? 

 
 
Country	 Year	 Variable	 2yearMA	 5YearMa	 Back2YearMa

Australia	 1897	 .	 .	 0	 .	 	
Australia	 1898	 .	 .	 0.5	 .	 	
Australia	 1899	 .	 .	 1	 .	 	
Australia	 1900	 .	 0	 1.5	 .	 	
Australia	 1901	 0	 0.5	 2	 .	 	
Australia	 1902	 1	 1.5	 3	 0	 	
Australia	 1903	 2	 2.5	 4	 0.5	 	
Australia	 1904	 3	 3.5	 5	 1.5	 	
Australia	 1905	 4	 4.5	 6	 2.5	 	
Australia	 1906	 5	 5.5	 7	 3.5	 	
Australia	 1907	 6	 6.5	 8	 4.5	 	
Australia	 1908	 7	 7.5	 9	 5.5	 	
Australia	 1909	 8	 8.5	 10	 6.5	 	
Australia	 1910	 9	 9.5	 11	 7.5	 	
Australia	 1911	 10	 10.5	 12	 8.5	 	
Australia	 1912	 .	 .	 .	 9.5	 	

Please access the attached hyperlink for an important electronic
communications disclaimer:
http://www.lse.ac.uk/collections/planningAndCorporatePolicy/legalandComplian
ceTeam/legal/disclaimer.htm

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index