Statalist


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

RE: st: help on user input in ado file


From   "Robert Zimmerman" <[email protected]>
To   <[email protected]>
Subject   RE: st: help on user input in ado file
Date   Fri, 29 Jun 2007 15:19:26 +0200

Thank you very much both Ulrich and Maarten for your suggestions. 

This is certainly helpful for future learning, and I will take your
recommendation of reading a text on programming at heart.

Ulrich, your solution only worked after changing the following line
reg res l.`res' `:subinstr local varlist "`yvar'" ""'

to:
reg `res' l.`res' `:subinstr local varlist "`yvar'" ""'

Best regards,
Robert

-----Oorspronkelijk bericht-----
Van: [email protected]
[mailto:[email protected]] Namens Ulrich Kohler
Verzonden: vrijdag 29 juni 2007 13:02
Aan: [email protected]
Onderwerp: Re: st: help on user input in ado file

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/


*
*   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