loop using sstats

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
paretto
Posts: 13
Joined: Tue Mar 30, 2010 11:02 am

loop using sstats

Unread post by paretto »

Dear Tom,

I have a couple of series where I stored teststatistics over a rolling window. I do want to compute the share of entries where the value is below 0.1.
I would like to loop over series claw1uipuk to claw24uipuk and store the computed share in the vector vcw. The sstats command for a single series works well, but if I substitute the name
of the series by the loop index "s" it's not working anymore. Whats the error? By the way how do I know which series are inside the loop index. How does rats exactly know over which series to loop?
Is it also possible to loop overseries, where more then one element changes? For example dofor s= claw1uipuk to claw24tayuk, where uip also changes to tay.


compute count = 1
dofor s = claw1uipuk to claw24uipuk
sstats(mean) 2007:01 2011:12 1 (s<0.1)>> vcw(count)
compute count=count+1
end dofor
write vcw

Thanks a lot !
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: loop using sstats

Unread post by TomDoan »

I don't know what the "1" is on this, and you need to get rid of the space between the >> and vcv(count)

sstats(mean) 2007:01 2011:12 1 (s<0.1)>> vcw(count)

However, the most important thing is that you need s{0}, not just s when s is an indirect reference to a series. That is, what you want is

sstats(mean) 2007:01 2011:12 (s{0}<0.1)>>vcw(count)

With that, it should work.
paretto
Posts: 13
Joined: Tue Mar 30, 2010 11:02 am

Re: loop using sstats

Unread post by paretto »

Dear Tom, I thank you for the quick and helpfull answers. It works.

I wanted to ask how rats is able to know over which series to loop. For example in stata I define a suffix "_i" to "_k" and I tell stata to loop over all series i to k. How does rats know, which series are included in the loop. Is it possible to loop over series where two items change at once? For example forecast_uk_1 to forecast_JP_3.

Thanks in advance!

Paul
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: loop using sstats

Unread post by TomDoan »

Assuming that those are the only series which have forecast_ as the prefix, you can do

dofor s = %slike("forecast_*")
...
end dofor s

If you are trying to restrict to a list built with combinations like UK_1 and JP_3, you would need to do a double loop over the country abbreviations and the horizons.

dofor [label] country = "UK" "DE" "CA" "JP"
dofor horizon = 1 2 3
compute s=%s("forecast_"+country+"_"+horizon)
....
end dofor horizon
end dofor label
Post Reply