How does one create a loop to do this for each month in a multi-year dataset?SET DUMMY1 = T>=2001:01:01.AND.T<2001:02:01
STATS(SMPL=DUMMY1) MYSERIES
SET(smpl=dummy1) DUMMY1 = sqrt(%variance)
Generating dummies using a loop
Generating dummies using a loop
The following creates a dummy that takes the value 1 in the first calendar month of a daily dataset, calculates basic stats of the variable MYSERIES for that month, and, finally, replaces the 1 values of the dummy with the standard deviation for MYSERIES:
Re: Generating dummies using a loop
This is an example:
Code: Select all
cal(d) 1947:1:1
all 1990:12:31
set junk = %ran(1.0)
set yymm = %year(t)*100+%month(t)
panel(group=yymm,id=yymmvalues)
set mysd 1 %size(yymmvalues) = %na
do i=1,%size(yymmvalues)
stats(noprint,smpl=(yymm==yymmvalues(i))) junk
compute mysd(i)=sqrt(%variance)
end do i
Re: Generating dummies using a loop
Thank you -this worked. I would like to do the same for the correlations between two variables. Would you be able to direct me as to what my commented line in the code below should include?TomDoan wrote:This is an example:
Code: Select all
cal(d) 1947:1:1 all 1990:12:31 set junk = %ran(1.0) set yymm = %year(t)*100+%month(t) panel(group=yymm,id=yymmvalues) set mysd 1 %size(yymmvalues) = %na do i=1,%size(yymmvalues) stats(noprint,smpl=(yymm==yymmvalues(i))) junk compute mysd(i)=sqrt(%variance) end do i
Code: Select all
cal(d) 1947:1:1
all 1990:12:31
set junk = %ran(1.0)
set morejunk = %ran(1.0)
set yymm = %year(t)*100+%month(t)
panel(group=yymm,id=yymmvalues)set mycorrs 1 %size(yymmvalues) = %na
do i=1,%size(yymmvalues)
* what instruction should I use here that produces %corr?
compute mycorrs(i) = %corr(junk,morejunk)
end do iRe: Generating dummies using a loop
Code: Select all
do i=1,%size(yymmvalues)
cmom(corr,smpl=(yymm==yymmvalues(i)))
# junk morejunk
compute mycorrs(i) = %cmom(1,2)
end do i