Page 1 of 1
DOFOR LABEL
Posted: Tue Sep 18, 2012 7:10 am
by comac
Hi there, I am trying to use DOFOR with labels or variables' names.
In the simplest case, I have two series named de
UK and de
JP which I intend to use as dependent variables. My regressors are named b
UK and b
JP.
Since '
UK' and '
JP' are recurring in my variables' names, I would like to implement something doing the following. All in one step:
Code: Select all
linreg deUK
#constant bUK
AND
linreg deJP
#constant bJP
I have tried something like this, but obviously this is not the right way in RATS:
Code: Select all
declare vector[labels] vl(2)
input vl
"UK" "JP"
dofor i = 1 2
linreg de'vl(i)'
#constant bvl(i)
end do for i
Many thanks in advance!
Re: DOFOR LABEL
Posted: Tue Sep 18, 2012 7:53 am
by TomDoan
Use the %S function to create the required series names:
Code: Select all
dofor [label] co = "uk" "jp"
linreg %s("de"+co)
# constant %s("b"+co)
end dofor
DOFOR LABEL
Posted: Tue Feb 19, 2013 11:25 pm
by economics2012
Hi,
I need to do a dofor loop for different series: aggregate, Agric, Food and Soda.
i.e. I need to repeat the linear regression below for Agric, Food and Soda,
Code: Select all
open data "aggregate.txt"
calendar(m) 1973:1
data(format=prn,nolabels,org=columns) 1973:01 2009:12 date oil o1 o2 o3 aggregate Agric Food Soda
smpl 1973:1 2009:12
ieval nlag=12
display 'use specification, nw errors'
linreg(robusterrors,lags=13,lwindow=neweywest) aggregate
# constant aggregate{1 to nlag} oil{1 to nlag} o1{1 to nlag}
exclude
# o1{1 to nlag}
display ' specification for 2-period, nw errors'
linreg(robusterrors,lags=13,lwindow=neweywest) aggregate
# constant aggregate{2 to nlag+1} oil{2 to nlag+1} o1{2 to nlag+1}
exclude
# o1{2 to nlag+1}
Any help?
Re: DOFOR LABEL
Posted: Wed Feb 20, 2013 10:17 am
by TomDoan
economics2012 wrote:Hi,
I need to do a dofor loop for different series: aggregate, Agric, Food and Soda.
i.e. I need to repeat the linear regression below for Agric, Food and Soda,
Code: Select all
open data "aggregate.txt"
calendar(m) 1973:1
data(format=prn,nolabels,org=columns) 1973:01 2009:12 date oil o1 o2 o3 aggregate Agric Food Soda
smpl 1973:1 2009:12
ieval nlag=12
display 'use specification, nw errors'
linreg(robusterrors,lags=13,lwindow=neweywest) aggregate
# constant aggregate{1 to nlag} oil{1 to nlag} o1{1 to nlag}
exclude
# o1{1 to nlag}
display ' specification for 2-period, nw errors'
linreg(robusterrors,lags=13,lwindow=neweywest) aggregate
# constant aggregate{2 to nlag+1} oil{2 to nlag+1} o1{2 to nlag+1}
exclude
# o1{2 to nlag+1}
Any help?
Code: Select all
dofor s = aggregate Agric Food Soda
linreg(robusterrors,lags=13,lwindow=neweywest) s
# constant s{1 to nlag} oil{1 to nlag} o1{1 to nlag}
exclude
# o1{1 to nlag}
display ' specification for 2-period, nw errors'
linreg(robusterrors,lags=13,lwindow=neweywest) s
# constant s{2 to nlag+1} oil{2 to nlag+1} o1{2 to nlag+1}
exclude
# o1{2 to nlag+1}
end door
Why are you doing Newey-West with 13 lags on the first regression? That should have serially uncorrelated errors.
Re: DOFOR LABEL
Posted: Wed Feb 20, 2013 10:33 am
by economics2012
Yes you are absolutely correct. For h>1, the errors are serially correlated.
Re: DOFOR LABEL
Posted: Wed Feb 20, 2013 11:09 am
by economics2012
One more question,
When I run the code for 50 different sectors,
Code: Select all
open data "dataset.txt"
calendar(m) 1973:1
data(format=prn,nolabels,org=columns) 1973:01 2009:12 date oil o1 o2 o3
aggregate agriculture Food Soda Beer Smoke Toys Fun Books Hshld Clths
Hlth MedEq Drugs Chems Rubbr Txtls BldMt Cnstr Steel FabPr Mach ElcEq
Autos Aero Ships Guns Gold Mines Coal Oil Util Telcm PerSv BusSv Hardw
Softw Chips LabEq Paper Boxes Trans Whlsl Rtail Meals Banks Insur RlEst
Fin Other
smpl 1973:1 2009:12
dofor s = aggregate agriculture Food Soda Beer Smoke Toys Fun Books Hshld Clths
Hlth MedEq Drugs Chems Rubbr Txtls BldMt Cnstr Steel FabPr Mach ElcEq
Autos Aero Ships Guns Gold Mines Coal Oil Util Telcm PerSv BusSv Hardw
Softw Chips LabEq Paper Boxes Trans Whlsl Rtail Meals Banks Insur RlEst
Fin Other
I got this error:
## I1. Expected Instruction - AGG Is Not Recognizable As One
>>>>aggregate <<<<
I think the line is too long or so...
I truly appreciate your help.
Re: DOFOR LABEL
Posted: Wed Feb 20, 2013 12:26 pm
by TomDoan
Some programming languages use a ; to indicate that a line is done, and keep running a single logical line until they see it. RATS uses the alternative of using a symbol ($ in our case) as the end of a line that isn't done. So you want
dofor s = aggregate agriculture Food Soda Beer Smoke Toys Fun Books Hshld Clths $
Hlth MedEq Drugs Chems Rubbr Txtls BldMt Cnstr Steel FabPr Mach ElcEq $
Autos Aero Ships Guns Gold Mines Coal Oil Util Telcm PerSv BusSv Hardw $
Softw Chips LabEq Paper Boxes Trans Whlsl Rtail Meals Banks Insur RlEst $
Fin Other
with something similar on the DATA instruction.
Re: DOFOR LABEL
Posted: Wed Feb 20, 2013 1:35 pm
by economics2012
Is there a way I can get the p-values results for 50 sectors across 12-horizons in one table?
It is a pain to copy each one of them into excel.
Thanks a lot.
Re: DOFOR LABEL
Posted: Wed Feb 20, 2013 3:09 pm
by TomDoan
Code: Select all
report(action=define)
dofor s = aggregate agriculture Food Soda Beer Smoke Toys Fun Books Hshld Clths $
Hlth MedEq Drugs Chems Rubbr Txtls BldMt Cnstr Steel FabPr Mach ElcEq $
Autos Aero Ships Guns Gold Mines Coal Oil Util Telcm PerSv BusSv Hardw $
Softw Chips LabEq Paper Boxes Trans Whlsl Rtail Meals Banks Insur RlEst $
Fin Other
report(row=new,atcol=1) %l(s)
do h=0,11
do the calculation for that horizon
report(row=current,atcol=h+2) whatever_the_pvalue_is_for_h
end do h
end do s
report(action=show,format=xls)
This will prompt you for the name of the Excel file you want to create. You could also put in an
open copy mytable.xls
command and use UNIT=COPY, or you could just do ACTION=SHOW without the FORMAT=XLS, and it will put the table up on the screen. You can then copy and paste the whole thing into Excel.
Re: DOFOR LABEL
Posted: Mon Mar 04, 2013 4:08 pm
by economics2012
Hi Tom,
What should I put for: whatever_the_pvalue_is_for_h?
I really appreciate your help
Re: DOFOR LABEL
Posted: Mon Mar 04, 2013 6:48 pm
by TomDoan
The idea was to avoid the copy-paste-edit steps for all the horizons. For a given value of h, you need
linreg(robusterrors,lags=13,lwindow=neweywest) s
# constant s{1+h to nlag+h} oil{1+h to nlag+h} size{1+h to nlag+h}
exclude
# size{1+h to nlag+h}
And the whatever_the_pvalue_is_for_h is just %SIGNIF
Re: DOFOR LABEL
Posted: Wed Mar 06, 2013 1:08 pm
by economics2012
Perfect. Thanks a lot, I truly appreciate it.
But in this case, I am doing Newey-West with 13 lags on the first regression which has serially uncorrelated errors. So should I change it?
Re: DOFOR LABEL
Posted: Wed Mar 06, 2013 1:16 pm
by TomDoan
Change to
linreg(robusterrors,lags=%if(h==0,0,13),lwindow=neweywest) s
which will give you "White" standard errors for h=0 and NW for h>0.
Re: DOFOR LABEL
Posted: Wed Mar 06, 2013 1:41 pm
by economics2012
Perfect. Thank you so much. You are very helpful.