Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Stas Kolenikov <skolenik@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: how to be -assert-ive |

Date |
Thu, 30 Sep 2010 07:52:54 -0500 |

This was the title of Bill Gould's Stata Tip#3 in the first issue of Stata Journal; over 10 years, it has received a whopping 2 citations. I wonder how often -assert-s are used in ado code? E.g., I know that some sort of -egen- command should retain the pattern of missing values from the source variable(s) to the newly generated variable; or a regression command should return R^2 between 0 and 1; or a prediction command should return non-negative values; after -mi-, I would expect the missing values to be replaced by non-missing; etc. Sometimes I do see -assert-s when I peek at the official Stata code, but not every program would use it. Bill Gould's recent "Missing manual" talk gives an example of prototypical code development in which the program goes into an ado file, and a test script checks its performance against the expected behavior using -assert-; and that's how certification would usually proceed (see another WG's paper in Stata Journal 1 (1) ). Now, I wonder if -assert-s in ado code is a desirable practice, and whether other people use it a lot. On short ten line programs, an extra couple of -assert-s means 20% increase in # of lines, and most likely a certain (although not necessarily a 20%) increase in execution time. On long programs where a lot is going on, including some convoluted -sort- operations, let alone numeric optimization or root finding, an extra -assert- or two or three or five are negligible in overall timing. As a matter of (i) good style and (ii) robust programming, do I need to put more -assert-s in my code? A command with similar intention is -confirm-, and again it is used in the official Stata code, usually to check inputs. And of course there is -assert()- in Mata, as well. -- Stas Kolenikov, also found at http://stas.kolenikov.name Small print: I use this email account for mailing lists only. * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**st: RE: how to be -assert-ive***From:*Nick Cox <n.j.cox@durham.ac.uk>

- Prev by Date:
**st: RE: Graphing: How to suppress labels on second y axis** - Next by Date:
**RE: st: RE: RE: RE: RE: RE: RE: RE: RE: RE: Foreach Command in Panel Data** - Previous by thread:
**Stata 12 wish list: mixed model negative binomial** - Next by thread:
**st: RE: how to be -assert-ive** - Index(es):