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: RE: Forvalues to make a moving average on non timeseries data.
From
Kieran McCaul <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: RE: Forvalues to make a moving average on non timeseries data.
Date
Tue, 18 Mar 2014 05:55:13 +0800
I think there are three problems here, although one must be a typo in your email, otherwise your program wouldn't even get to the "weights not allowed" error.
So I'll assume two problems.
If you insert the following before the first -forvalues- statement:
set trace on
set tracedepth 1
You will find the line that the error message is referring to.
If you fix that, you'll then get some output which will point you to the second problem.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Snapp, Kevin Michael
Sent: Monday, 17 March 2014 11:50 PM
To: [email protected]
Subject: st: Forvalues to make a moving average on non timeseries data.
Hello Stata-nauts
I have to make a disclosure, this is for a homework assignment. I've emailed the professor but I haven't had a response yet, as its spring break. We are working through the Cameron and Trivedi "Microeconometrics Using Stata." On pp 71 there is a problem I can't figure out, #6. I am asked to sort a selection of PSID data by hours worked (hours) then calculated a moving average of the log of earnings
(lnearns) for a section of the data. The book suggests using forvalues, but I can't figure it out for the life of me. I've searched the statalist and found something similar but still no luck.
Here is my first attempt:
observations 2037 through 2053 are the ones I need a moving average for. My plan was to get the sum of the 25 observations and then dived by 25 in a separate step.
generate MA = .
forvalues i = 2037/2053 {
forvalues j -12/12 {
quietly replace MA[`i'] =( MA[`i'] + lnearns[`j' + `i'])
}
}
The error message I get says weights not allowed
I have tried it without nesting:
generate MA = .
forvalues j -12/12 {
quietly replace MA = MA + lnearns[`j']
}
and it runs, but it doesn't change any values (afterwards there are 0 observations of MA).
Any advice is appreciated
Regards
Kevin Snapp
IUPUI Economics
[email protected]
*
* 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/