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: AW: Tssmooth Ma Missing Values
From
"Martin Weiss" <[email protected]>
To
<[email protected]>
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: [email protected]
[mailto:[email protected]] Im Auftrag von
[email protected]
Gesendet: Donnerstag, 25. März 2010 11:55
An: [email protected]
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/