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: Regression and Looping
From
Nick Cox <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Regression and Looping
Date
Sun, 2 Mar 2014 23:20:19 +0000
This sounds confused. -ID- as e.g. "01Jan03" could not be the result
of applying -string()- to a numeric variable unless you also specified
a date format. In any case, if you have an integer date variable, it
should not need conversion to string for this purpose.
That said, this sounds like some misunderstanding of your data.
I tend to use -statsby- for this kind of exercise. Here is a silly example:
. webuse grunfeld, clear
. statsby a0=_b[_cons] a1=_b[mvalue] , by(year) : regress invest mvalue
(running regress on estimation sample)
In your case it sounds as if you just should try
statsby a0=_b[_cons] a1=_b[return_m] , by(dt) : regress return_p return_m
Nick
[email protected]
On 2 March 2014 22:58, Reese Andorfer <[email protected]> wrote:
> I have an industry portfolio with at the respective return return_p
> and then I the return of the market portfolio return_m. My time period
> is 10 years and I have the returns- on a monthly basis.
>
> Now I would like to perform the following regression : reg return_p
> return_m for every month in my 10 year time period.
>
> I would like to save the constant as well as the beta coefficient for
> return_m, thus I tried to use the following :
>
> gen ID=string( dt)
>
>
> gen a0=.
> gen a1=.
>
>
> levelsof ID, local(x)
> foreach obs of local x {
> reg return_p return_m if ID=="`obs'"
> replace a0=_b[_cons] if ID=="`obs'"
> replace a1=_b[return_m] if ID=="`obs'"
> }
>
>
> whereby ID - is the date of the observation f.e. 01Jan03 in string form
>
> now I have no missing observations whatsoever and I get the error no
> observations.
*
* 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/