RATS 10.1
RATS 10.1

OS( options )   command line to run

OS (DOS is an obsolete synonym) runs the command line using a shell to the operating system. This can be used to (for instance) fetch a data file from an external web site. While it may be possible to achieve that in some cases by using a properly designed URL UNIT option on the DATA instruction (see the URL example in the description of OPEN), whether you can do that will depend upon the design of the web site. You can also use it to send information to be processed by another program.

 

By default, RATS waits until the command is finished to continue. For instance, this means that you can run an external program (such as Python or R) to generate and save a data file, then follow with OPEN DATA and DATA instructions to read it using RATS. However, you can also use the NOWAIT option if you are sending information to another program and have no need to wait on a result.

 

If the command line has any embedded spaces (which will almost always be the case), you need to enclose it in "...". If there are further spaces within that (inside a file name for instance), you need to use '...' within that. For instance,

 

os "python c:\rats\'data tests'\testfredpython.py"

 

Options

[WAIT]/NOWAIT

If WAIT (the default), execution of the RATS commands is paused until the external program is finished.

 

Examples

The RATS program:

 

os "python c:\rats\'data tests'\testfredpython.py"

open data c:\temp\sp500fred.csv

cal(d) 2014:1:1

data(format=prn,org=columns)

 

which calls the Python program


from fredapi import Fred

fred = Fred(api_key='your FRED API key')

data = fred.get_series('SP500')

data.rename('SP500',inplace=True)

data.to_csv(r'c:/temp/sp500fred.csv',index=True, header=True)

 

pulls the series SP500 out of FRED and copies it to a labeled, dated file named c:/temp/sp500fred.csv. The RATS program uses that as the data file. (Note that this could have been done directly with DATA(FORMAT=FRED); it's offered as a simple example of the use of OS).

 

The following (which is based upon the GCONTOUR.RPF example) writes information for creating a 3D graph in R. The first Excel file has the coordinates for the grid and the second has the corresponding log likelihoods.

 

compute nbreaks=10

compute nmus=10

*

compute breaks=%seqrange(1.0,100.0,nbreaks)

compute mus   =%seqrange(0.2, 20.0,nmus)

*

* This generates as "over" the sum of x for elements above t.

*

acc x / ax

set over = ax(100)-ax(t)

*

* Compute the sum of squares

*

compute x2=%normsqr(x)

*

* Generate the log likelihood for all the combinations of mus and breaks.

*

dec rect z(nbreaks,nmus)

ewise z(i,j)=thisBreak=breaks(i),thisMu=mus(j),$

    300-50.0*log((x2-2*thisMu*over(fix(thisBreak))+(100-thisBreak)*thisMu^2)/100.0)

*

* open the target copy file, write to it, then close it before starting the R process

*

open copy c:\temp\graph3daxes.xlsx

write(format=xlsx,unit=copy) breaks~mus

close copy

*

open copy c:\temp\graph3ddata.xlsx

write(format=xlsx,unit=copy) z

close copy

os(wait) "rscript graph3ddata.r"

 

A simple R program for doing the graph is

 

library(readxl)

library(rgl)

 

axisdata <- read_excel("c:/temp/graph3daxes.xlsx",col_names=c("brkpt","mu"))

logldata <- read_excel("c:/temp/graph3ddata.xlsx",col_names=FALSE)

x = axisdata$brkpt

y = axisdata$mu

z = data.matrix(logldata)

open3d()

persp3d(x,y,z,col="lightblue",xlab="Break Pt",ylab="mu",

   zlab="LogL",box=TRUE,ticktype="simple",theta=50,phi=25,shade=0.5)

surface3d(x, y, z, back = "lines")

surface3d(x, y, z, front = "lines")

rgl.snapshot("c:/temp/testpng.png",fmt="png")

 

Output

Any output written to "standard output" or "standard error" by the command line will be inserted into the RATS output file.

 


Copyright © 2025 Thomas A. Doan