Bookmark and Share

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: RE: forval predict values into same column


From   "Jesper Lindhardsen" <[email protected]>
To   <[email protected]>
Subject   st: RE: forval predict values into same column
Date   Mon, 24 Jan 2011 21:31:57 +0100

Hej Mike,

Regarding Q1 I would use -egen rowmax- or -egen rownonmiss- to gather the data in one column after the loop, e.g., 

..loop..

Egen jointpredictvar=rowmax(y1hat*)


As for Q2 you can do it several ways. One approach could be

egen maxgroup=max(groupid)
Local n = maxgroup[1]

Forval i=1/`n' {

Regards, 

Jesper



Jesper Lindhardsen
MD, Ph.d. student
Department of Cardiovascular Research
Copenhagen University Hospital, Gentofte
Denmark






-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Michael Bondegård
Sent: 24 January 2011 21:15
To: [email protected]
Subject: st: forval predict values into same column

Hello,
1. question 1

I wonder how to make this
forval i=1/6 {
regress Y1 X1 X2 if GROUPID ==`i'
predict Y1HAT if e(sample)
}

When i do this it tells me  Y1HAT already defined (so it stops after
second run, return just values first time)

I know that i can do this:
forval i=1/6 {
regress Y1 X1 X2 if GROUPID ==`i'
predict Y1HAT_`i' if e(sample)
}

As you see i add same number to the predictor that way i can go trough
this problem but what i want is to put the prediction in same column
from the start.

This is because the GROUPID is diffrent for each prediction so it wont
overwrite anything once it input the prediction values into it.

2, question 2
How to make return a maximum value for the GROUPID, as you see in the
example above the forval runs 6 timas (6 is the max in GROUPID)

My question is, is there any way to make the similar to this wish:
forval i=1/MAX(GROUPID)

I been looking for the right answer but no luck:(

Thanks for help
best regards Mike
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index