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.

DOFOR LABEL

Postby comac » Tue Sep 18, 2012 7:10 am

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

Re: DOFOR LABEL

Postby TomDoan » Tue Sep 18, 2012 7:53 am

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
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

DOFOR LABEL

Postby economics2012 » Wed Feb 20, 2013 12:25 am

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?
economics2012
 
Posts: 62
Joined: Thu Jan 19, 2012 5:41 pm

Re: DOFOR LABEL

Postby TomDoan » Wed Feb 20, 2013 11:17 am

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.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: DOFOR LABEL

Postby economics2012 » Wed Feb 20, 2013 11:33 am

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

Re: DOFOR LABEL

Postby economics2012 » Wed Feb 20, 2013 12:09 pm

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 2:45 pm, edited 1 time in total.
economics2012
 
Posts: 62
Joined: Thu Jan 19, 2012 5:41 pm

Re: DOFOR LABEL

Postby TomDoan » Wed Feb 20, 2013 1:26 pm

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.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: DOFOR LABEL

Postby economics2012 » Wed Feb 20, 2013 2:35 pm

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.
economics2012
 
Posts: 62
Joined: Thu Jan 19, 2012 5:41 pm

Re: DOFOR LABEL

Postby TomDoan » Wed Feb 20, 2013 4:09 pm

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.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: DOFOR LABEL

Postby economics2012 » Mon Mar 04, 2013 5:08 pm

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 2:42 pm, edited 1 time in total.
economics2012
 
Posts: 62
Joined: Thu Jan 19, 2012 5:41 pm

Re: DOFOR LABEL

Postby TomDoan » Mon Mar 04, 2013 7:48 pm

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
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: DOFOR LABEL

Postby economics2012 » Wed Mar 06, 2013 2:08 pm

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?
economics2012
 
Posts: 62
Joined: Thu Jan 19, 2012 5:41 pm

Re: DOFOR LABEL

Postby TomDoan » Wed Mar 06, 2013 2:16 pm

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.
TomDoan
 
Posts: 2720
Joined: Wed Nov 01, 2006 5:36 pm

Re: DOFOR LABEL

Postby economics2012 » Wed Mar 06, 2013 2:41 pm

Perfect. Thank you so much. You are very helpful.
economics2012
 
Posts: 62
Joined: Thu Jan 19, 2012 5:41 pm


Return to Help With Programming

Who is online

Users browsing this forum: No registered users and 0 guests