Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Multiple commands under "By varlist"?

From   "Nick Cox" <>
To   <>
Subject   st: RE: Multiple commands under "By varlist"?
Date   Sat, 26 Jun 2004 13:18:30 +0100

The short answer is that -by:- cannot 
be extended in this way. But there 
are several nearly equivalent procedures. 

Scott Merryman suggested -statsby- 
which is one good answer. You may 
or may not want the data reduction 
(collapsing of the data) that produces. 

You could write a program to be "byable". 
That way, an arbitrarily complex operation 
can be carried out by your own program. 

For this kind of example, however, an approach 
based on -forval- or -foreach- is indicated. 
You may want something like 

gen tintcp = . 
gen tslope = . 
forval i = 1/12 {
	regress returns factor if month == `i' 
	replace tintcp = _b[_con] if month == `i' 
	replace tslope = _b[factor] if month == `i' 

There is a much fuller discussion at


Subhankar Nayak
> Is it possible to give multiple commands following a particular
> by varlist command?
> Can I give something like:
> by month: {
> regress returns factor
> replace tintcp = _b[_con]
> replace tslope = _b[factor]
> }
> Of course, what I give here is not working, but is there 
> anyway to make it functional?

*   For searches and help try:

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