Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: help on user input in ado file


From   "Maarten Buis" <[email protected]>
To   <[email protected]>
Subject   st: RE: help on user input in ado file
Date   Fri, 29 Jun 2007 13:55:47 +0200

--- Robert Zimmerman wrote:
> I am trying to write an ado file to automate a series of commands, but I am
> completely new to Stata programming so all I get is error messages. Hope you
> can help.
> 
> Here is my routine:
>
> local y="y"
> local xlist="x1 x2"
> reg `y' `xlist'
> predict res, r
> reg res l.res `xlist'
> est table, keep(l.res) p
> drop res
>
> I would like to be able to have y, x1 , x2 etc. as user input, so that
> myprog.ado would work with:  myprog y x1 x2

*--------------- begin example -----------
capture program drop myprog
program define myprog
	version 9.2
	syntax varlist [if] [in] [pw aw fw]
	gettoken y xlist : varlist
	if "`weight'" != "" local wgt `"[`weight'`exp']"'
	marksample touse
	qui reg `y' `xlist' if `touse' `wgt'
	tempvar res
	qui predict `res' if `touse', r 
	qui reg `res' l.`res' `xlist' if `touse' `wgt'
	est table, keep(l.`res') p
end

sysuse auto, clear
gen t = _n
tsset t
myprog price mpg foreign
*----------------- end example ----------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index