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]

Re: st: RE: How to get coefficient and R square from time series regression


From   Xixi Lin <[email protected]>
To   statalist <[email protected]>
Subject   Re: st: RE: How to get coefficient and R square from time series regression
Date   Tue, 24 Sep 2013 09:47:29 -0400

Thanks, Joe.

Best,
Xixi Lin

On Mon, Sep 23, 2013 at 11:33 AM, Joe Canner <[email protected]> wrote:
> Xixi,
>
> Since you are using -capture-, how about taking advantage of the return code that it generates:
>
> forvalues z=1/1894 {
> capture reg NIBE_RS NIBE_RSL if ID==`z'
> if (_rc==0) {
>   replace EQ1=_b[NIBE_RSL] if ID==`z'
>   replace EQ2=e(r2) if ID==`z'
> }
> }
>
> Using this method you don't even have to delete IDs with <=2 observations, because this will work for any error, whether it be "no observations" or "insufficient observations".
>
> Regards,
> Joe
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Xixi Lin
> Sent: Monday, September 23, 2013 10:03 AM
> To: statalist
> Subject: Re: st: RE: How to get coefficient and R square from time series regression
>
> Hi Joe,
>
> You are right, some ID only has 1 or 2 observations, which render the error. However, if I delete them, there would be incomplete number list of IDs, then I can not use forvalues z=1/1894 since there are some gaps in between them. Do you happen to have a solution to solve this? Thanks.
>
> Best,
> Xixi Lin
>
> On Sat, Sep 21, 2013 at 4:55 PM, Joe Canner <[email protected]> wrote:
>> Xixi,
>>
>> One more question: Are there at least two observations for each ID
>> from 1 to 1894?  Linear regression with one independent variable
>> cannot be done with only one observation.  (I'm not sure what effect
>> tsset has in this case; I don't do much with time series.)
>>
>> In any case, I would recommend, for debugging purpses, removing the
>> -capture- before the -reg-, so that you can see what happens right
>> before you get the "no variables defined error".  My guess is that
>> there is an error in the -reg- statement, which you are not seeing
>> because of -capture- and then when you try to use the _b[] and r[]
>> vectors they do not exist and you get "no variables defined".  (I was
>> able to reproduce this behavior for several kinds of regression
>> errors, including "insufficient" observations.)
>>
>> Regards,
>> Joe
>>
>> ________________________________________
>> From: [email protected]
>> [[email protected]] on behalf of Xixi Lin
>> [[email protected]]
>> Sent: Friday, September 20, 2013 3:44 PM
>> To: statalist
>> Subject: Re: st: RE: How to get coefficient and R square from time
>> series regression
>>
>> Hi Joe,
>>
>> When I changed it into forvalues z=1/1894, it works in the beginning,
>> and then stops, showing the following errors: no variables defined, do
>> you know why?
>>
>> Thanks,
>> Xixi Lin
>>
>> On Fri, Sep 20, 2013 at 3:01 PM, Joe Canner <[email protected]> wrote:
>>> forvalues z=1/1894
>>>
>>> -----Original Message-----
>>> From: [email protected]
>>> [mailto:[email protected]] On Behalf Of Xixi Lin
>>> Sent: Friday, September 20, 2013 2:59 PM
>>> To: statalist
>>> Subject: st: How to get coefficient and R square from time series
>>> regression
>>>
>>> Hi,
>>>
>>> The following is the code I am using to generate coefficient and R
>>> square, but it gives errors as:invalid numlist has too many elements
>>>
>>> gen EQ1= .
>>> gen EQ2= .
>>> tsset Period
>>> foreach z of numlist 1/1894{
>>> capture reg NIBE_RS NIBE_RSL if ID==`z'
>>> replace EQ1=_b[NIBE_RSL] if ID==`z'
>>> replace EQ2=e(r2) if ID==`z'
>>> }
>>>
>>> Does anyone knows how to fix it? Thanks.
>>>
>>> Best,
>>> Xixi Lin
>>> *
>>> *   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/
>>>
>>> *
>>> *   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/
>> *
>> *   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/
>>
>> *
>> *   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/
>
> *
> *   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/
>
> *
> *   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/

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


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