Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Stata 程序中如何使用语法?_Stata_Stata Macros - Fatal编程技术网

Stata 程序中如何使用语法?

Stata 程序中如何使用语法?,stata,stata-macros,Stata,Stata Macros,我已经在Stata中多次使用程序命令 今天,我试图教自己如何创建一个使用输入的程序。我试过查看语法帮助文件和的第71页,但我不知道如何做到这一点 如果您能给我看一些详细介绍这个特定主题的文档,我将不胜感激。或者在下面指出我做错了什么 如您所见,我只想创建一个短程序,检查指定文件夹中是否存在文件(capture confirm file),但如果有错误(window stopbox note),我想显示自己的对话框,如果有错误,然后有序地退出do文件(exit 601) 返回错误: 不允许使用因子

我已经在Stata中多次使用
程序
命令

今天,我试图教自己如何创建一个使用输入的程序。我试过查看
语法
帮助文件和的第71页,但我不知道如何做到这一点

如果您能给我看一些详细介绍这个特定主题的文档,我将不胜感激。或者在下面指出我做错了什么

如您所见,我只想创建一个短程序,检查指定文件夹中是否存在文件(
capture confirm file
),但如果有错误(
window stopbox note
),我想显示自己的对话框,如果有错误,然后有序地退出
do
文件(
exit 601

返回错误:

不允许使用因子变量和时间序列运算符
r(101)

我不知道如何使用
语法
获取文件夹路径和文件名。请注意,这些通常是字符串,但我猜:

"`folder'/`file'"
例如,如果输入是用引号完成的,将导致出现
“C:\Users\User\Documents”/“NIDSw5.dta”
,因此我认为应该使用
本地(输入)
方法

还要注意,我将使用全局变量(
$DataIN
)而不是将文件夹路径字符串放在那里,并且文件名包含附加到字符串上的全局变量

删除
varlist,
会导致错误:

无效语法
r(197)


以下是我的作品:

program checkfile
syntax, folder(string) file(string)
capture confirm file "`folder'/`file'"
if _rc == 601 {
    window stopbox note `"`file' is not in `folder'"' 
    exit 601
}
end
然后,您只需键入:

checkfile, folder(C:\Users\User\Documents) file(NIDSw5.dta)

编辑:

您也可以在不使用以下选项的情况下执行此操作:

program checkfile
capture confirm file "`1'/`2'"
if _rc == 601 {
    window stopbox note `"`2' is not in `1'"'
    exit 601
}
end

checkfile C:\Users\User\Documents NIDSw5.dta
program checkfile
capture confirm file "`1'/`2'"
if _rc == 601 {
    window stopbox note `"`2' is not in `1'"'
    exit 601
}
end

checkfile C:\Users\User\Documents NIDSw5.dta