Robert Zimmerman wrote:
> Dear Statalist,
>
> 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
There is much to say, but here is an example to start with. 
--------------myprog.ado
program myprog
version 9
syntax varlist
quietly {
	tempvar res
	reg `varlist'
	predict `res', r
	local yvar: word 1 of `varlist'
	reg res l.`res' `:subinstr local varlist "`yvar'" ""'
}
estimates table, keep(l.`res') p
end 
--------------------------
-tsset- must be used before the program can be used. You should take care of 
this within your program. 
I recommend to take a look at an introductional text for programming in Stata. 
Chapter 11 of the "Data Analysis Using Stata" by Frauke Kreuter and myself 
comes to my mind.
many regards
Uli
-- 
Ulrich Kohler
[email protected]
030/25491-361
*
*   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/