Home  /  Products  /  Stata 8  /  Programming features

This page contains only historical information and is not about the current release of Stata. Please see our features page for information on the current version of Stata.

Programming features in Stata 8

  • Object-oriented programming has been added to Stata. Classes are defined by the new class command in .class files. Among other features, classes provide inheritance, encapsulation of data structures and programs, and program name overloading. Stata's new graphics and new GUI are implemented via classes.

  • Stata has a new GUI, which is programmable. Dialog boxes are created in .dlg files.

  • Stata has new programmable graphics.

  • The new serset command is another part of Stata's new graphics, though its use is not limited to graphics. A serset is a collection of variables from a dataset that coexists in memory along with the current dataset, and whose values can be accessed quickly. The new serset command creates and manipulates sersets.

  • SMCL has three additions. The new {ccl} directive outputs the value contained in a constant and current-value class (c()) object. {center:text} now also allows {center #:text}, which specifies that text be centered within a width of # columns. {dialog dialogname:text} launches a dialog box.

  • The new markin command—for use after marksample, mark, and markout—creates a macro containing the smallest in range that contains the if exp.

  • The new c class contains constants, such as the value of pi and current values of system parameters and settings. Typing creturn list displays the current settings.

    Many macro extended functions have disappeared; that is, they have disappeared from the documentation, even though they still work. For instance, to find out whether more was on or off, there was set more, but it is now gone. c(more) returns the more setting, and lots more. This is not only more logical, but it is now easier to find these settings; just type creturn list.

  • The define in program define myprog is now optional.

  • New set trace ... features make debugging programs easier.

    set traceexpand specifies whether a line in a program is to be shown both before and after macro expansion.

    set tracedepth specifies the level of nesting to be included in the trace.

    set tracesep specifies whether a horizontal separator line that displays the name of the subroutine is displayed in the trace whenever a subroutine is called or exits.

    set traceindent specifies whether the displayed lines of code are indented according to their nesting level.

    set tracenumber specifies whether the nesting level is displayed at the front of the program lines.

  • The new comment indicators // and /// allow new ways of specifying comments and joining lines in do-files and ado-files.

  • The postfile command now allows you to post string variables! postfile now accepts a newvarlist rather than a varlist, so storage types may be specified, including strings.

  • The new macro assignment commands local ++lclname and local --lclname may be used to increment and decrement lclname.

  • Macro expansion now allows ++ and -- prefix and suffix operators. `++a' means to increment a by 1 and substitute the resulting value. `a++' means substitute the current value of a and then to increment it by 1. `--a' and `a--' do the same thing, except that they decrement.

  • Macro expansion now allows evaluation of expressions, such as `=2*(`i'+1)', and allows the use of macro extended functions, such as `: var label `myvar''.

  • A new macro expansion function macval(lclname) gives the contents of lclname as is, without recursive expansion.

  • Five new macro extended functions have been added, which are mentioned below. (Another nine new macro extended functions have been added to support the use of the new serset command mentioned above).

    The new macro extended function list allows manipulations of lists (think lists of variable names, lists of filenames, etc.). For instance, a|b forms the union of a and b without repeating in the results the elements that are in both a and b. a&b returns the intersection (elements in both a and b).

    The new macro extended function constraint gives information on constraints.

    The new macro extended function permname assists in naming variables.

    The new macro extended function dir obtains file and directory names.

    The new macro extended function length returns the length in characters of a macro.
  • The syntax command has two new descriptors:

    The new namelist descriptor provides an alternative to the varlist descriptor. namelist relaxes the restriction that the names that the user types be variable names. namelist can be specified in place of varlist at the front of a command, and namelist can be specified inside option arguments.

    The new anything descriptor makes it easier for programmers to parse almost-standard syntax, that is, nonstandard syntax up to if, in, weight, or options, and standard syntax thereafter.

  • gettoken has two new options: bind and qed(lmacname). bind specifies that expressions within parentheses or brackets be bound together, even when not parsing on () and []. qed() specifies a local macroname to be filled in with 1 or 0 according to whether the returned token was enclosed in quotes in the original string.

  • assert has a new option null that forces a return code of 8 on null assertions.

  • confirm has two new subcommands: confirm matrix and confirm scalar.

  • The new findfile command looks for a file along a specified path and returns the name in r(fn).

  • The new file command allows programmers to read and write both ASCII text and binary files.

  • The new matrix opaccum command forms a new matrix based on the outer product, within a specified group, of a specified variable.

  • The new matrix eigenvalues command calculates eigenvalues of nonsymmetric matrices.

  • The new unabcmd command returns a Stata command in unabbreviated form.

  • save has a new emptyok option that allows saving datasets with no variables or observations, and merge and append have been certified to work with empty datasets. Thus, in loops that build datasets, you no longer have to treat the first addition specially. You can create an empty result at the outset and then just append or merge to the previous result.

  • describe using has a new varlist option that specifies that the saved results r(varlist) and r(sortlist) be saved along with the other saved results. r(varlist) will contain the names of the variables in the dataset, and r(sortlist) will contain the names of the variables by which the data are sorted. Thus, you no longer have to use a dataset to find out about it.

  • You can now obtain the random-number seed at one point in a program and reset it in another:
            . ...
            . local seed = "`c(seed)'"
            . ...
            . set seed `seed'
            . ...
    


  • The new programming functions maxbyte(), maxdouble(), maxfloat(), maxint(), maxlong(), minbyte(), mindouble(), minfloat(), minint(), and minlong() find the largest and smallest number of each numerical data type. epsdouble() and epsfloat() give the smallest step size for floating-point and double-precision numbers. The function byteorder() gives the byte order for writers of binary files, and irecode() is another flavor of the recode() function.

  • The new programming functions chop() and clip() return x rounded to an integer and x within a range.

  • The new matrix functions are issym(), which determines if a matrix is symmetric; matuniform(), which makes a matrix filled with uniformly distributed random numbers; matmissing(), which indicates if elements of a matrix are missing; hadamard(), which computes the Hadamard product of two matrices; and vec(), which turns a matrix into a column vector.

  • The new string function plural() makes plurals, proper() obtains the correct capitalization, word() finds a specific word of a string, and wordcount() counts the number of words in a string.

  • The new math functions include tanh(), the hyperbolic tangent, and its inverse, atanh(); logit() and invlogit(); and cloglog(), the complimentary log-log function, and its inverse, invcloglog(). New functions ceil() and floor() find the least integer greater than x and the greatest integer less than x, respectively.

  • The new probability distribution and density functions include the first and second derivatives for the gamma distribution, dgammapda(), dgammapdada(), dgammapdadx(), dgammapdx(), and dgammapdxdx(). A variety of density functions have been added: betaden(), gammaden(), nbetaden(), tden(), Fden(), and nFden() for calculating both central and noncentral distributions. New distribution functions and inverses are nibeta(), invnibeta(), nFtail(), and invnFtail().

  • Existing function cond(x,a,b,[d]) now has an optional fourth argument that is returned in case x evaluates to missing. If the fourth argument is not specified, x=missing returns b.

  • Existing function recode(x,x_1,x_2,..., x_n) now returns missing if the sequence is not weakly increasing. x_i = . is interpreted as +infinity.

  • Existing function round(x[.y]) now allows the argument y, which specifies the unit of rounding, to be optional.