Stata 11 help for m1_source

help m1 source -------------------------------------------------------------------------------

Title

[M-1] source -- Viewing the source code

Syntax

. viewsource functionname.mata

Description

Many Mata functions are written in Mata. viewsource will allow you to examine their source code.

Remarks

Some Mata functions are implemented in C (they are part of Mata itself), and others are written in Mata.

viewsource allows you to look at the official source code written in Mata. Reviewing this code is a great way to learn Mata.

The official source code is stored in .mata files. To see the source code for [M-5] diag(), for instance, type

. viewsource diag.mata

You type this at Stata's dot prompt, not at Mata's colon prompt.

If a function is built in, such as [M-5] abs(), here is what will happen when you attempt to view the source code:

. viewsource abs.mata file "abs.mata" not found r(601);

You can verify that abs() is built in by using the mata which (see [M-3] mata which) command:

. mata: mata which abs() abs(): built-in

viewsource can be also used to look at source code of user-written functions if the distribution included the source code (it might not).

Also see

Manual: [M-1] source

Help: [P] viewsource; [M-1] intro


© Copyright 1996–2009 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index