Statalist


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

st: RE: by with multiple commands


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: by with multiple commands
Date   Fri, 2 May 2008 15:53:51 +0100

I don't know what you expect Stata to do with all the output that is
produced separately for each -by- group. For example, do you want
separate matrices b, beta, v for each group? I guess you do. 

It is more likely perhaps that you want to loop over the groups,
something like this: 

egen group = group(myvar) 
su group, meanonly 
forval i = 1/`r(max)' { 
	probit ... if group == `i' 
	wtpcikr  ... if group == `i' 
	matrix b`i' = e(b)
	matrix beta`i' = b`i'/-b`i'[1,1]
	...
} 

See also 

FAQ     . . . . . . . . . . Making foreach go through all values of a
variable
        8/05    Is there a way to tell Stata to try all values of a
                particular variable in a foreach statement without
                specifying them?
                http://www.stata.com/support/faqs/data/foreach.html

SJ-2-2  pr0005  . . . . . .  Speaking Stata:  How to face lists with
fortitude
        Q2/02   SJ 2(2):202--222                                 (no
commands)
        demonstrates the usefulness of for, foreach, forvalues, and
        local macros for interactive (non programming) tasks

<http://www.stata-journal.com/article.html?article=pr0005>


Nick 
[email protected] 

Henrik Andersson

I need to run identical regressions for different subsamples of my data
set. I have one variable that defines the different subsamples and I
would like to use this variable together with the "by" command. My
problem is that my regressions contain several command.

My regressions, together with my "post estimation" commands, look like

probit yes lnbid lninc if bid<=income 
wtpcikr lnbid lninc if bid<=income, mym(mean1) expo
matrix b=e(b)
matrix beta=b/-b[1,1]
matrix v=e(V)/(b[1,1]^2)
ereturn post beta v, noclear
ereturn display
scalar sigma=1/-b[1,1]
display sigma

Using my variable that defines the different subsamples, I would like to
run the string of commands above for each subsample. Is this possible
using the "by" command? 


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