RATS procedures: loop and dec function

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.
apple
Posts: 2
Joined: Sat Jun 18, 2016 12:03 am

RATS procedures: loop and dec function

Unread post by apple »

This may be a very basic question but I wish create a 100x1 vector (I name it "temp") that has the values of draws from standard normal distribution using a loop. Here is an attempt that I made but I am not sure if I am declaring the correct type to start with. Further, how do I compute the average and standard deviation of "temp" and show these statistics in the output window?

dec vect temp(100)

do i = 1,100
compute temp(i) = %ran(1)
end do i

%mean(temp)
%sqrt(%variance(temp))
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: RATS procedures: loop and dec function

Unread post by TomDoan »

You don't have to do a loop---%ran will apply to all elements of a vector.

You need a DISPLAY instruction to show the information.
dec vect temp(100)
compute temp=%ran(1.0)
disp %mean(temp)
disp sqrt(%variance(temp))
apple
Posts: 2
Joined: Sat Jun 18, 2016 12:03 am

Re: RATS procedures: loop and dec function

Unread post by apple »

Thank you for your reply. I have run the above code and obtained the following error "## Unassigned 117 >>>>disp %mean(<<<<" Could you kindly tell me what this error means? Thanks.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: RATS procedures: loop and dec function

Unread post by TomDoan »

Is there a reason you want a VECTOR rather than a SERIES?

set temp 1 100 = %ran(1.0)
stats temp

would give you the mean, variance and and more. For computing those for a VECTOR, you would use %AVG(temp) to compute the mean and %COV(temp,temp) to compute the variance.
Post Reply