Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65037

Preferred syntax for incorporating optional weights into a program

$
0
0
I've written a simple program which creates a graph after collapsing some data. I want to add the option of including an analytic weight to the collapse, but I want the use of a weight to be optional. The documentation on the syntax command is a little thin and I couldn't find any good descriptions of best practices in incorporating an optional weight. Combing through the programs which have optional weights was a little overwhelming because the code snippets which handle the weights are often heavily interweaved with handlers for other options.

Basically, I want the program to optionally take an analytic weight. From my understanding of the syntax statement, you need to specify what types of weights are allowable, so you need to type [aweight] rather than [weight]
Code:
program def graphit
    syntax varlist(min=1) [if] [in] [aweight], By(varname) [SOMEoptions(real 1) SCHeme(passthru)]
...
...
   collapse (mean) `var' if `touse' [`weight' `exp'], by(`by')
...
In this case, if there is no optional weight, the expression [`weight' `exp'] will evaluate to [] and the program will continue as if nothing was specified.

I've inspected a bunch of programs which seem to be specifying a bunch of conditional if ... branches to catch missing weights. Is the above behavior an acceptable way of coding this, or is there some potential error that I need to catch which I'm not seeing?



Viewing all articles
Browse latest Browse all 65037

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>