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: Dropping Program Saved as an ado-file


From   Maarten Buis <[email protected]>
To   [email protected]
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''"
	}
	
	subprog
end

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
end

sysuse auto
mainprog price mpg foreign
*-------------------- end example ---------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )

Hope this helps,
Maarten

---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------
*
*   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/


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