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

st: VB: RE: by with multiple commands

From   "Henrik Andersson" <>
To   <>
Subject   st: VB: RE: by with multiple commands
Date   Fri, 2 May 2008 18:48:07 +0200

Dear Nick,

thanks for your help. forval does exactly what I want.


-----Ursprungligt meddelande-----

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
        8/05    Is there a way to tell Stata to try all values of a
                particular variable in a foreach statement without
                specifying them?

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



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:

*   For searches and help try:

© Copyright 1996–2023 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index