How to run ado file in another ado file in Stata?
In 开发者_StackOverflowR, I can run another R script using
source("script.R")
How can I do the same in Stata?
In Stata, there are two types of scripts:
- There are do-files, which are sequences of the commands as you type them, which may contain pretty much anything, and
- There are ado-files, which are self-contained program scripts. Ado stands for "Automatically loaded DO files".
The primary distinction is that to execute the do-file, you need to do
it or run
it:
do whatever.do
shows the output, and
run whatever.do
suppresses the output.
The automatically loaded do-files, as the name implies, are loaded automatically. When you type
blah blah1 blah2
Stata will first look for the program blah
in its memory. If it is not there, it will look for file blah.ado
in the subdirectories identified in its adopath
that by default includes Stata's own directories, as well as the current directory (type adopath
to find out more, if you are interested). If it finds this blah.ado
, it will (1) make sure it has program define blah
inside it, and (2) try to execute this program with whatever arguments you supplied (blah1 blah2
). If it fails to find the file blah.ado
anywhere, it will issue an error message:
. blah blah1 blah2
unrecognized command: blah
r(199);
Stata will search for the ado file in the default directories as the top answer indicated. To see your system default directories, type:
. sysdir
You can manually change the directory (e.g., the PERSONAL path) for ado files to the folder you like, using:
. sysdir set PERSONAL "C:\your-ado-folder"
Credit: https://kb.iu.edu/d/arur
精彩评论