Bookmark and Share

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, is already up and running.

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

Re: st: Dropping Program Saved as an ado-file

From   Maarten Buis <>
Subject   Re: st: Dropping Program Saved as an ado-file
Date   Wed, 5 Sep 2012 11:20:18 +0200

On Wed, Sep 5, 2012 at 10:31 AM, Maarten Buis wrote:
> I assume you have a main program, which calls -ml-, which calls your
> likelihood evaluator program, and that you want to create temporary
> variables in your main program and use those in your likelihood
> evaluator program.
> The trick is that temporary variables continue to exist as long as the
> program that created them has not ended. So all you need is a way to
> pass on the names of those temporary variables from your main program
> to your likelihood evaluator program. This can be done with global
> macros.

Here is an example program based on this outline:

*------------------- begin example --------------------
clear all

program define mainprog
	version 12.1
	syntax varlist
	gettoken y x : varlist
	tempvar yvar
	qui gen `yvar' = `y' / 100
	global yvar "`yvar'"

	// make sure $xvars starts empty
	macro drop xvars
	foreach var of local x {
		tempvar x`var'
		// I admit, this is silly
		qui gen `x`var'' = `var'/_pi
		global xvars "$xvars `x`var''"

program define subprog
	version 12.1
	di as txt "Dispay summary of " as result "yvar"
	sum $yvar
	di _n as txt "Dislay summary of " as result "xvars"
	sum $xvars

sysuse auto
mainprog price mpg foreign
*-------------------- end example ---------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Reichpietschufer 50
10785 Berlin
*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index