复用 Stata 中的代码行,类似于 JavaScript 函数?
Reuse lines of code in Stata, Similar to JavaScript function?
我在 Stata do 文件中有一些代码行我想 reuse/execute 和 do 文件中的不同点。类似于 JavaScript 函数...但是我不一定需要输入变量。
比如我有一段代码:
*code to reuse
foreach x in test1 test2 test3{
rename variable_`x' variablenew_`x'
}
我想在 do 文件的不同位置执行这 3 行代码。好像有一种方法可以在 do 文件中标记这三行 codeA
然后 execute codeA
。
有什么建议吗?
勾选help program
。
示例程序(不带参数):
// define program
capture program drop hello
program hello
display "hello world!"
end
// try it out
hello
我在 Stata do 文件中有一些代码行我想 reuse/execute 和 do 文件中的不同点。类似于 JavaScript 函数...但是我不一定需要输入变量。
比如我有一段代码:
*code to reuse
foreach x in test1 test2 test3{
rename variable_`x' variablenew_`x'
}
我想在 do 文件的不同位置执行这 3 行代码。好像有一种方法可以在 do 文件中标记这三行 codeA
然后 execute codeA
。
有什么建议吗?
勾选help program
。
示例程序(不带参数):
// define program
capture program drop hello
program hello
display "hello world!"
end
// try it out
hello