📄 mkassert.hlp
字号:
{smcl}
{* 10mar2005}{...}
{cmd:help mkassert}{right:also see: {help undocumented}}
{hline}
{title:Title}
{p 4 18 2}
{hi:mkassert} {hline 2} Generate asserts for Stata objects
{title:Syntax}
{p 8 24 2}
{cmd:mkassert} {cmdab:r:class}
[{cmd:,}
{cmdab:mf:mt:(}{it:fmt}{cmd:)}
{cmdab:mt:ol:(}{it:tol}{cmd:)}
{cmdab:sf:mt:(}{it:fmt}{cmd:)}
{cmdab:st:ol:(}{it:tol}{cmd:)}
{cmdab:mw:rap:(}{it:#}{cmd:)}
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
{p 8 24 2}
{cmd:mkassert} {cmdab:e:class}
[{cmd:,}
{cmdab:mf:mt:(}{it:fmt}{cmd:)}
{cmdab:mt:ol:(}{it:tol}{cmd:)}
{cmdab:sf:mt:(}{it:fmt}{cmd:)}
{cmdab:st:ol:(}{it:tol}{cmd:)}
{cmdab:mw:rap:(}{it:#}{cmd:)}
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
{p 8 24 2}
{cmd:mkassert} {cmdab:scl:ass}
[
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
{p 8 24 2}
{cmd:mkassert} {cmdab:m:atrix} {it:name-list}
[{cmd:,}
{cmdab:mf:mt:(}{it:fmt}{cmd:)}
{cmdab:mt:ol:(}{it:tol}{cmd:)}
{cmdab:mw:rap:(}{it:#}{cmd:)}
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
{p 8 24 2}
{cmd:mkassert} {cmdab:sca:lar} {it:name-list}
[{cmd:,}
{cmdab:sf:mt:(}{it:fmt}{cmd:)}
{cmdab:st:ol:(}{it:tol}{cmd:)}
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
{p 8 24 2}
{cmd:mkassert} {cmdab:c:har}{space 3}[{it:name-list}]
[{cmd:,}
{cmd:dta}
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
{p 8 24 2}
{cmd:mkassert} {cmdab:o:bs}{space 4}[{it:varlist}] [{cmd:if} {it:exp}] [{cmd:in} {it:range}]
{cmd:,} {cmd:id(}{it:varlist}{cmd:)}
[
{cmdab:c:omputed:(}{it:spec}{cmd:)}
{cmdab:n:ame:(}{it:str}{cmd:)}
{it:save_opt}
]
where
{p 8 24 2}{it:tol}{space 8}is{space 3}{it:#} | {it:name} | {it:name} {it:#}
{p 8 24 2}{it:save_opt}{space 3}is{space 3}{cmdab:sav:ing:(}{it:filename}{cmd:,} [{cmd:append} | {cmd:replace}]{cmd:)}
{title:Description}
{pstd}{cmd:mkassert} generates a set of {helpb assert} statements for the
current contents of one of the following Stata "objects":
{p 8 16 2}{cmd:eclass}{space 2}macros, scalars, and matrices in {cmd:e()}
{p 8 16 2}{cmd:rclass}{space 2}macros, scalars, and matrices in {cmd:r()}
{p 8 16 2}{cmd:sclass}{space 2}macros in {cmd:s()}
{p 8 16 2}{cmd:matrix}{space 2}one or more matrices
{p 8 16 2}{cmd:scalar}{space 2}one or more scalars
{p 8 16 2}{cmd:char}{space 4}the characteristics associated with the variables
in {it:varlist}, and/or those associated with the dataset
{p 8 16 2}{cmd:obs}{space 5}the values of variables in (a selection of)
observations
{pstd}
To enhance readability, the output uses formatting such as alignment and
colors. The assert statements can be copied from the Review window into a
certification script (see {helpb cscript}). Alternatively, you can have
{cmd:mkassert} write a log file (see {helpb log}).
{pstd}
If macro texts can be interpreted as integers and reals, asserts are
generated that test numerical equality (in case of reals: after conversion
to float). Integer scalar values are tested with strict equality rather
than some tolerance.
{title:Options}
{phang}
{cmd:mfmt(}{it:fmt}{cmd:)}
is the format used to convert matrix elements to ascii. It defaults
to %18.0g.
{phang}
{cmd:mtol(}{{it:#}|{it:name}|{it:name} {it:#}}{cmd:)}
specifies the tolerance {it:#} for {hi:mreldif}-testing of matrices.
If {it:#} is not specified, it defaults to 1e-8. If {it:name} is
specified, a local macro {it:name} is defined equal to {it:#}, and all
tests in the block refer to {it:name}.
{phang}
{cmd:sfmt(}{it:fmt}{cmd:)}
is the format used to convert scalars to ascii. It defaults to %18.0g.
{phang}
{cmd:stol(}{{it:#}|{it:name}|{it:name} {it:#}}{cmd:)}
specifies the tolerance for {hi:reldif}-testing of scalars. The syntax
is described with the option {cmd:mtol}.
{phang}
{cmd:mwrap(}{it:#}{cmd:)}
specifies that {cmd:mkassert} performs element wrapping in generating input
commands for a matrix with {it:#} or more columns. The default is 4.
{phang}
{cmd:name(}{it:str}{cmd:)}
specifies that each {cmd:assert} statement that is generated is
accompanied by a reference {it:str#} within a comment and numbered
sequentially.
{phang}
{cmd:dta}
specifies that certification statements should be written for the
characteristics associated with the data set {cmd:_dta}.
{phang}
{cmd:id(}{it:varlist}{cmd:)}
specifies one of more variables that identify the observations (form a
key). These variables are used to match the current observations with
those during certification. The {it:if-exp} and {it:in-range} clauses
are evaluated after the data are sorted on the {cmd:id} variables.
{phang}
{cmd:computed(}{it:spec}{cmd:)}
specifies the real-valued variables that are "computed" and have to be
{hi:reldif}-tested rather than equality-tested. The specification
{it:spec} is a varlist with optionally embedded numbers that are the
tolerances used in {hi:reldif}-testing for all following variables
until overruled by another number. The tolerance defaults to 1e-10.
{pmore}{it:Example}: {cmd:computed(1e-8 price weight 1e-7 trunk mpg)}
specifies that {cmd:price} and {cmd:weight} are {hi:reldif}-tested with
tolerance 1e-8, and {cmd:trunk} and {cmd:mpg} with tolerance 1e-7.
{phang}
{cmd:saving(}{it:filename} [{cmd:,} {cmd:append} | {cmd:replace}]{cmd:)}
opens a text-only file with {cmd:mkassert} output to be included in a
certification script.
{title:Example}
{cmd:. summ price}
{txt} Variable | Obs Mean Std. Dev. Min Max
{txt}-------------+-----------------------------------------------------
{txt} price |{res} 74 6165.257 2949.496 3291 15906{txt}
{cmd:. ret list}
{txt:scalars:}
{txt:r(N) =}{res: 74}
{txt:r(sum_w) =}{res: 74}
{txt:r(mean) =}{res: 6165.256756756757}
{txt:r(Var) =}{res: 8699525.974268789}
{txt:r(sd) =}{res: 2949.495884768919}
{txt:r(min) =}{res: 3291}
{txt:r(max) =}{res: 15906}
{txt:r(sum) =}{res: 456229}
{cmd:. mkassert rclass}
{txt}assert{space 9}r({res:N}) {col 25}== {res}74
{txt}assert{space 9}r({res:sum_w}) {col 25}== {res}74
{txt}assert reldif( r({res:mean}) {col 25} , {res}6165.256756756757{txt}{col 46}) < {res} 1e-8
{txt}assert reldif( r({res:Var}) {col 25} , {res}8699525.974268789{txt}{col 46}) < {res} 1e-8
{txt}assert reldif( r({res:sd}) {col 25} , {res}2949.495884768919{txt}{col 46}) < {res} 1e-8
{txt}assert{space 9}r({res:min}) {col 25}== {res}3291
{txt}assert{space 9}r({res:max}) {col 25}== {res}15906
{txt}assert{space 9}r({res:sum}) {col 25}== {res}456229
{pstd}
{txt}If you were writing a certification script for {cmd:summarize},
you would copy the command line and the associated output from
{cmd:mkassert rclass} into the script, maybe deleting unimportant
{cmd:assert}s. You can of course modify the tolerances, but notice
the tolerance options to modify the tolerance for all tests, or
"parametrize" the tests via a named constant in the {cmd:mtol} and
{cmd:stol} options.
{title:Acknowledgment}
{pstd}
{cmd:mkassert} was written by Jeroen Weesie, Dept of Sociology,
Utrecht University, the Netherlands.
{title:Also see}
{psee}
Online: {helpb assert}, {helpb cscript}, {helpb return},
{helpb savedresults}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -