Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[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., 


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' {



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

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

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:

*   For searches and help try:

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