Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Is there a way to use or emulate the behaviour of --predict-- with --by-- groups?
From
Aaron Kirkman <[email protected]>
To
[email protected]
Subject
st: Is there a way to use or emulate the behaviour of --predict-- with --by-- groups?
Date
Tue, 30 Oct 2012 19:40:58 -0500
Dear Statalist,
I have data grouped by a variable called --group--, in this example,
and I'm trying to use logarithmic interpolation on another variable.
Linear interpolation using the --ipolate-- command works perfectly in
--by-- group, as shown:
****
clear
quietly input str1 group x y
A 1 1000
A 2 .
A 3 3000
A 4 .
B 5 45
B 6 .
B 9 20
end
bysort group: ipolate y x, g(y_linear) e
list, noobs sepby(group)
****
Unfortunately, this does not work with logarithmic interpolation and
--regress--/--predict--.
****
gen lgx = log(x)
bysort group: regress y lgx
by group: predict y_loginterp, xb
****
This returns error r(190): "predict may not be combined with by." I
know I can use matrix commands to save these variables in the dataset
if I'm not using --by--:
****
regress y lgx
matrix beta = e(b)
svmat double beta, names(matcol)
list, clean noobs
**
group x y lgx betalgx beta_cons
A 1 1000 0 -602.68868 1755.3384
A 2 . .6931472 . .
A 3 3000 1.098612 . .
A 4 . 1.386294 . .
B 5 45 1.609438 . .
B 6 . 1.791759 . .
B 9 20 2.197225 . .
Unfortunately, this only stores the values of beta for the last
regression run, where group == "B". Is there a way to perform what I'm
trying to do? The actual data set is much larger and would probably
involve several hundred regressions of this type.
Thank you,
Aaron
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/