DOFOR LABEL

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.
comac
Posts: 25
Joined: Mon Jun 29, 2009 7:31 am

DOFOR LABEL

Unread post by comac »

Hi there, I am trying to use DOFOR with labels or variables' names.
In the simplest case, I have two series named deUK and deJP which I intend to use as dependent variables. My regressors are named bUK and bJP.
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!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR LABEL

Unread post 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
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

DOFOR LABEL

Unread post 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?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR LABEL

Unread post 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.
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

Re: DOFOR LABEL

Unread post by economics2012 »

Yes you are absolutely correct. For h>1, the errors are serially correlated.
Last edited by economics2012 on Wed Mar 06, 2013 1:45 pm, edited 2 times in total.
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

Re: DOFOR LABEL

Unread post 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.
Last edited by economics2012 on Wed Mar 06, 2013 1:45 pm, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR LABEL

Unread post 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.
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

Re: DOFOR LABEL

Unread post 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.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR LABEL

Unread post 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.
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

Re: DOFOR LABEL

Unread post by economics2012 »

Hi Tom,


What should I put for: whatever_the_pvalue_is_for_h?

I really appreciate your help
Last edited by economics2012 on Wed Mar 06, 2013 1:42 pm, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR LABEL

Unread post 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
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

Re: DOFOR LABEL

Unread post 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?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: DOFOR LABEL

Unread post 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.
economics2012
Posts: 51
Joined: Thu Jan 19, 2012 4:41 pm

Re: DOFOR LABEL

Unread post by economics2012 »

Perfect. Thank you so much. You are very helpful.
Post Reply