Statalist The Stata Listserver


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

Re: st: running do files from unix -- can we pass values to the do file?


From   Richard Williams <[email protected]>
To   [email protected]
Subject   Re: st: running do files from unix -- can we pass values to the do file?
Date   Sat, 18 Feb 2006 12:03:18 -0500

At 11:37 AM 2/18/2006, Pablo Mitnik wrote:


An elegant and efficient alternative would be to be able to pass the values of the locals to the do file when running it, something like:

stata -b do dofile localvalue1 localvalue2 &

Of course, this cannot be done this way.
Sure it can. Include an -args- command in your do file.

Here is a simple example. This is xtest.do:

use "http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta";
args v1 v2
ologit warm `v1' `v2', nolog

To execute it:

. do c:\ado\personal\xtest yr89 male

. use "http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta";
(77 & 89 General Social Survey)

. args v1 v2

. ologit warm `v1' `v2', nolog

Ordered logistic regression Number of obs = 2293
LR chi2(2) = 129.53
Prob > chi2 = 0.0000
Log likelihood = -2931.0051 Pseudo R2 = 0.0216

------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
yr89 | .5897259 .0784044 7.52 0.000 .436056 .7433958
male | -.6349161 .0773504 -8.21 0.000 -.7865201 -.4833122
-------------+----------------------------------------------------------------
/cut1 | -2.036695 .0809737 -2.1954 -1.877989
/cut2 | -.2968644 .0661125 -.4264425 -.1672863
/cut3 | 1.499808 .0736113 1.355533 1.644084
------------------------------------------------------------------------------

.
end of do-file

. do c:\ado\personal\xtest white age

. use "http://www.indiana.edu/~jslsoc/stata/spex_data/ordwarm2.dta";
(77 & 89 General Social Survey)

. args v1 v2

. ologit warm `v1' `v2', nolog

Ordered logistic regression Number of obs = 2293
LR chi2(2) = 109.78
Prob > chi2 = 0.0000
Log likelihood = -2940.8797 Pseudo R2 = 0.0183

------------------------------------------------------------------------------
warm | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
white | -.3218748 .1166027 -2.76 0.006 -.5504119 -.0933378
age | -.0226439 .0022927 -9.88 0.000 -.0271375 -.0181503
-------------+----------------------------------------------------------------
/cut1 | -3.266496 .1621334 -3.584272 -2.948721
/cut2 | -1.526333 .1492848 -1.818926 -1.23374
/cut3 | .2578696 .1466078 -.0294763 .5452156
------------------------------------------------------------------------------

.
end of do-file



-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: [email protected]
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
*
* 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