Differences between revisions 3 and 6 (spanning 3 versions)
Revision 3 as of 2023-06-08 00:38:36
Size: 811
Comment:
Revision 6 as of 2025-10-24 16:02:16
Size: 799
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Reusable functions can be defined in the Stata programming language as '''programs'''. '''Programs''' are reusable functions.
Line 11: Line 11:
== Definition == == Description ==
Line 13: Line 13:
Stata programs are defined using the `program` command.

{{{
program foo
  args a b
  if "`b'"=="" {
    di "Expected 2 arguments (got 1)"
    exit
  }
  gen `a'=`b'
end
}}}

----



== Usage ==
Programs are defined and manipulated using the '''`-program-`''' command.
Line 44: Line 27:
Use `program list _all` to list the contents of all programs. ----



== Usage ==

The following is the declaration of a simple program that takes two arguments.

{{{
program foo
  args a b
  if "`b'"=="" {
    di "Expected 2 arguments (got 1)"
    exit
  }
  gen `a'=`b'
end
}}}

Stata Programs

Programs are reusable functions.


Description

Programs are defined and manipulated using the -program- command.

To list all defined programs, try:

program dir

To examine a program, try:

program list foo


Usage

The following is the declaration of a simple program that takes two arguments.

program foo
  args a b
  if "`b'"=="" {
    di "Expected 2 arguments (got 1)"
    exit
  }
  gen `a'=`b'
end

To delete a program, try:

program drop foo

Use program drop _all to delete all programs and program drop _allado to delete all programs that were loaded from ado files.


CategoryRicottone

Stata/Programs (last edited 2025-10-24 16:02:16 by DominicRicottone)