Statalist


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

RE: st: Question about the syntax command


From   Maarten buis <[email protected]>
To   stata list <[email protected]>
Subject   RE: st: Question about the syntax command
Date   Sun, 6 Sep 2009 21:10:01 +0000 (GMT)

--- L S wrote:
> I am having difficulty using the Stata syntax command.

Below is an example that illustrate how you can debug such
programs and at the bottom are two solutions.

*----------------------- begin example ---------------------
clear
set obs 100
set seed 1234
gen y = uniform()
gen x = uniform()
gen z = uniform()
gen clus = (z>.5)

capture program drop toyreg
program toyreg
	syntax varlist , CLUSTER(varname)
	gettoken y xvars : varlist
	di "the local CLUSTER contains: " `"`CLUSTER'"'
	di "the local cluster contains: " `"`cluster'"'
	reg `y' `xvars', `CLUSTER'
end

toyreg y x, cluster(clus)

// one solution
capture program drop toyreg
program toyreg
	syntax varlist , CLUSTER(passthru)
	gettoken y xvars : varlist
	di "the local CLUSTER contains: " `"`CLUSTER'"'
	di "the local cluster contains: " `"`cluster'"'
	reg `y' `xvars', `cluster'
end
toyreg y x, cluster(clus)

// another solution
capture program drop toyreg
program toyreg
	syntax varlist , CLUSTER(varname)
	gettoken y xvars : varlist
	di "the local CLUSTER contains: " `"`CLUSTER'"'
	di "the local cluster contains: " `"`cluster'"'
	reg `y' `xvars', cluster(`cluster')
end
toyreg y x, cluster(clus)
*------------------- end example -----------------------
( For more on how to use examples I sent to statalist see:
http://www.maartenbuis.nl/stata/exampleFAQ.html )

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index