Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Time series analysis by subsets within data set


From   Michael Hanson <[email protected]>
To   [email protected]
Subject   Re: st: Time series analysis by subsets within data set
Date   Thu, 12 Apr 2007 22:38:30 -0400

On Apr 12, 2007, at 5:40 PM, Michael Crain wrote:

My data set looks like this:
Week
Customer
Sales

I want to perform time series analysis on EACH CUSTOMER. I cannot figure out how to run the time series commands (e.g., graphics, arima) on each customer seperately within a single data set.

On Apr 12, 2007, at 9:32 PM, Scott Merryman wrote:
Use the -if qualifier- :

arima sales if customer == "name", ar(1)

On Apr 12, 2007, at 9:56 PM, Michael Crain wrote:
Thank you, Scott, but I cannot get the TSSET set in the first place. When I issue the TSSET command, I get an error message "repeated time values in sample."

An example of my data set (using weekly data) looks like this:

2003w1 (customer name 1) (amount)
2003w1 (customer name 2) (amount)
2003w1 (customer name 3) (amount)
2003w2 (customer name 1) (amount)
2003w2 (customer name 2) (amount)
2003w2 (customer name 3) (amount)
2003w3 (customer name 1) (amount)
2003w3 (customer name 2) (amount)
2003w3 (customer name 3) (amount)
Of course -tsset- won't work with repeated values for the same date... until you tell it you have panel data, that is. Try the following: (*untested*!)

. encode customer, gen(cust_no) // Create customer numbers
. tsset cust_no week
. arima sales if customer == "customer name 2", ar(1)
. arima sales if cust_no == 2, ar(1)

If you want to get a bit more fancy, you could attempt something like:

. bysort cust_no: arima sales, ar(1)

but I cannot promise that will work as expected.

Hope this helps.

-- Mike
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index