Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: ado Stata file


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: ado Stata file
Date   Fri, 16 Nov 2012 14:06:26 -0500

At 11:00 AM 11/16/2012, Chiara Mussida wrote:
Dear All,
Does anybody know how to do transform a program written in a dofile
(which contains an index) in an adofile, and therefore into a Stata
command?

A few answers have appeared. I would add...

There are a few rules that are best to stick to when creating a command. That is, while any program can be made into a command (an ado), it is recommended to follow some "good programming" rules in doing so. I often allow myself to be a bit sloppy when just creating a program as part of a do-file, but try to make it "clean" when creating a command.

Don't reference or generate specific-named variables. Instead, use tempvars or names passed via a -syntax- statement. In either of these cases, you reference the names as local macros. But this rule is sometimes violated, using names that start with an underscore. And then it is clearly documented. (Think of _merge.)

Don't clear the in-memory dataset without the user specifying a "clear" option that you put in the -syntax-. Don't -replace- values without the user specifying a "replace" option that you put in the -syntax-. (Think of the -destring- command.) Those last two items can be summarized as -- Try not to make it easy for a user to accidentally clobber data; make it so that a user needs to write specific command elements or options before a significant change in data occurs.

I'm sure there are more of these principles, and other List-members may chime in, but this should get you started.
HTH
--David

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index