proper use of if

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

proper use of if

Rodrigo Briceño-4
Dear Stata Listers. I'm using Stata 9.2 and Windows XP.

I have a panel with 324 bonds (identified with the variable isin2)
with 54 observations in time (monthly series). I'm running several
individual (for each bond) time series regression:

quietly regress liq sap liqmk m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 mes
pprom if isin2==1
predict ehat, res

When I run the command the residuals are generated for all the 17496
observations, instead of just 54 observations as correctly
corresponds. My question to the list is if there are some command that
allows me to produce the required results just for the 54 observations
considered each time. I'm using if, since not all the 324 bonds are
going to be used in the regression process.

Thanks.

--
Rodrigo Briceño
Economist
[hidden email]
MSN: [hidden email]
SKYPE: rbriceno1087

*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: proper use of if

Nick Cox
If you read -help predict- you will see that it explains that -predict- also takes -if- if you wish. As you did not specify -if-, predictions were generated for the whole dataset, which people sometimes do want. So, just repeat -if isin2 == 1- on the -predict-.

Nick
[hidden email]

Rodrigo Briceño

I'm using Stata 9.2 and Windows XP.

I have a panel with 324 bonds (identified with the variable isin2)
with 54 observations in time (monthly series). I'm running several
individual (for each bond) time series regression:

quietly regress liq sap liqmk m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 mes
pprom if isin2==1
predict ehat, res

When I run the command the residuals are generated for all the 17496
observations, instead of just 54 observations as correctly
corresponds. My question to the list is if there are some command that
allows me to produce the required results just for the 54 observations
considered each time. I'm using if, since not all the 324 bonds are
going to be used in the regression process.


*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: proper use of if

Sergiy Radyakin
In reply to this post by Rodrigo Briceño-4
predict ehat if e(sample), res

On Tue, Nov 16, 2010 at 11:32 AM, Rodrigo Briceño <[hidden email]> wrote:

> Dear Stata Listers. I'm using Stata 9.2 and Windows XP.
>
> I have a panel with 324 bonds (identified with the variable isin2)
> with 54 observations in time (monthly series). I'm running several
> individual (for each bond) time series regression:
>
> quietly regress liq sap liqmk m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 mes
> pprom if isin2==1
> predict ehat, res
>
> When I run the command the residuals are generated for all the 17496
> observations, instead of just 54 observations as correctly
> corresponds. My question to the list is if there are some command that
> allows me to produce the required results just for the 54 observations
> considered each time. I'm using if, since not all the 324 bonds are
> going to be used in the regression process.
>
> Thanks.
>
> --
> Rodrigo Briceño
> Economist
> [hidden email]
> MSN: [hidden email]
> SKYPE: rbriceno1087
>
> *
> *   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/
Reply | Threaded
Open this post in threaded view
|

Re: proper use of if

Rodrigo Briceño-4
thanks to Nick and Sergiy for their responses. I'm clear now about what to do.

2010/11/16 Sergiy Radyakin <[hidden email]>:

> predict ehat if e(sample), res
>
> On Tue, Nov 16, 2010 at 11:32 AM, Rodrigo Briceño <[hidden email]> wrote:
>> Dear Stata Listers. I'm using Stata 9.2 and Windows XP.
>>
>> I have a panel with 324 bonds (identified with the variable isin2)
>> with 54 observations in time (monthly series). I'm running several
>> individual (for each bond) time series regression:
>>
>> quietly regress liq sap liqmk m2 m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 mes
>> pprom if isin2==1
>> predict ehat, res
>>
>> When I run the command the residuals are generated for all the 17496
>> observations, instead of just 54 observations as correctly
>> corresponds. My question to the list is if there are some command that
>> allows me to produce the required results just for the 54 observations
>> considered each time. I'm using if, since not all the 324 bonds are
>> going to be used in the regression process.
>>
>> Thanks.
>>
>> --
>> Rodrigo Briceño
>> Economist
>> [hidden email]
>> MSN: [hidden email]
>> SKYPE: rbriceno1087
>>
>> *
>> *   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/
>



--
Rodrigo Briceño
Economist
[hidden email]
MSN: [hidden email]
SKYPE: rbriceno1087

*
*   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/
Reply | Threaded
Open this post in threaded view
|

Re: proper use of if

Christopher Baum-2
In reply to this post by Rodrigo Briceño-4
On Nov 17, 2010, at 2:33 AM, Nick wrote:

> If you read -help predict- you will see that it explains that -predict- also takes -if- if you wish. As you did not specify -if-, predictions were generated for the whole dataset, which people sometimes do want. So, just repeat -if isin2 == 1- on the -predict-.

A perhaps even better solution is to predict... if e(sample), as that will not only incorporate the if condition on the regression, but avoid predicting for any observations which could not be included in the estimation.

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: Re: proper use of if

Nick Cox
I agree that -if e(sample)- is a good piece of syntax to know, but otherwise I don't see a practical difference here.

If the observations couldn't be included, the result will be missing and the consequence is the same.

Nick
[hidden email]

Christopher Baum

A perhaps even better solution is to predict... if e(sample), as that will not only incorporate the if condition on the regression, but avoid predicting for any observations which could not be included in the estimation.

On Nov 17, 2010, at 2:33 AM, Nick wrote:

> If you read -help predict- you will see that it explains that -predict- also takes -if- if you wish. As you did not specify -if-, predictions were generated for the whole dataset, which people sometimes do want. So, just repeat -if isin2 == 1- on the -predict-.



*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: Re: proper use of if

Rodrigo Briceño-4
thanks Nick and Cristopher. I decided to use "if e(sample)" and it
worked perfectly.

2010/11/17 Nick Cox <[hidden email]>:

> I agree that -if e(sample)- is a good piece of syntax to know, but otherwise I don't see a practical difference here.
>
> If the observations couldn't be included, the result will be missing and the consequence is the same.
>
> Nick
> [hidden email]
>
> Christopher Baum
>
> A perhaps even better solution is to predict... if e(sample), as that will not only incorporate the if condition on the regression, but avoid predicting for any observations which could not be included in the estimation.
>
> On Nov 17, 2010, at 2:33 AM, Nick wrote:
>
>> If you read -help predict- you will see that it explains that -predict- also takes -if- if you wish. As you did not specify -if-, predictions were generated for the whole dataset, which people sometimes do want. So, just repeat -if isin2 == 1- on the -predict-.
>
>
>
> *
> *   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/
>



--
Rodrigo Briceño
Economist
[hidden email]
MSN: [hidden email]
SKYPE: rbriceno1087

*
*   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/
Reply | Threaded
Open this post in threaded view
|

re: proper use of if

Christopher Baum-2
In reply to this post by Rodrigo Briceño-4
<>
Nick said

I agree that -if e(sample)- is a good piece of syntax to know, but otherwise I don't see a practical difference here.

If the observations couldn't be included, the result will be missing and the consequence is the same.


Well, not quite so. If the dependent variable was missing but the RHS variables were not, -predict- could create a prediction for those observations.  Repeating the if condition would not catch that, but e(sample) would.

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
                              An Introduction to Stata Programming  |   http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html


*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: re: proper use of if

Nick Cox
Good point. The choice comes down to what the user prefers, but predictions you don't want can always be ignored or overwritten in any case.

Nick
[hidden email]

Christopher Baum

Nick said

I agree that -if e(sample)- is a good piece of syntax to know, but otherwise I don't see a practical difference here.

If the observations couldn't be included, the result will be missing and the consequence is the same.


Well, not quite so. If the dependent variable was missing but the RHS variables were not, -predict- could create a prediction for those observations.  Repeating the if condition would not catch that, but e(sample) would.


*
*   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/
Reply | Threaded
Open this post in threaded view
|

RE: proper use of if

Allan Reese (Cefas)
In reply to this post by Rodrigo Briceño-4
Nick Cox <[hidden email]> recommended
> If you read -help predict- you will see that it explains that
-predict- also takes -if- if you wish.
> As you did not specify -if-, predictions were generated for the whole
dataset, which people sometimes do want.
> So, just repeat -if isin2 == 1- on the -predict-.

True, but more generally, after any model fit you can use the saved flag
on the estimation commands:
   predict ... if e(sample)

Another corollary of the -if- notation is you can predict from one model
into more than one variable, making it easier to graph fitted values and
extrapolations with different line styles.

Allan


***********************************************************************************
This email and any attachments are intended for the named recipient only.  Its unauthorised use, distribution, disclosure, storage or copying is not permitted.  If you have received it in error, please destroy all copies and notify the sender.  In messages of a non-business nature, the views and opinions expressed are the author's own and do not necessarily reflect those of the organisation from which it is sent.  All emails may be subject to monitoring.
***********************************************************************************


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