Hi there,
I'm new of programming and this is the first time to write a Eviews code.
I was trying to get the standard deviation of residuals to estimate the idiosyncratic risk of my portfolios. I used daily returns (y1 to y11) as my dependent variables, X1 X2 represents indexes returns and X3 represents currency returns. I have a daily data from 02/02/2009 to 11/03/2016, but I was trying to get the quarterly standard deviation of residuals to run the crosssectional regression. I was managed to run this daily data 1865 times to get residuals, however, my data was not sorted by quarters and not following logic order, that is , sample periods between 1 to 42 represent 2009Q1, 43 to 107 represent 2009Q2 and so on. So I have to manually set up my testing periods.( this may sounds stupid)
Now I'm trying find alternative ways to write this codes to make it looks better and don't have to manually change the series name. Please see the attachment for my codes.
Any help would be highly appreciated!
Estimating standard deviation of residuals by using Loop
Moderators: EViews Gareth, EViews Jason, EViews Moderator
Estimating standard deviation of residuals by using Loop
 Attachments

 loop.prg
 (2.11 KiB) Downloaded 24 times

 EViews Developer
 Posts: 161
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Estimating standard deviation of residuals by using Loop
Hello,
First, you're needlessly performing the exact same regression 1856 times, it doesn't need to be inside a loop. The regression will automatically cover all the observations (or the current sample). Second, you can calculate the quarterly standard deviations much more compactly via @stdevsby, e.g.: @stdevsby(e11, @quarter, @year).
First, you're needlessly performing the exact same regression 1856 times, it doesn't need to be inside a loop. The regression will automatically cover all the observations (or the current sample). Second, you can calculate the quarterly standard deviations much more compactly via @stdevsby, e.g.: @stdevsby(e11, @quarter, @year).
Re: Estimating standard deviation of residuals by using Loop
Hello Matt,
Thank you for your replay. Your code worked perfectly.
Now I've got a new question regarding the structure of my data. I have 11 firms, 7 variables, 29 firmquarters. However, only 3 variables contain 11 crosssectional data (11 series in one company), the other 4 only have timeseries data(one series in one company) . Therefore, this cannot be structured as panel or pool and will lead to "Near singular matrix ". Should I create an unbalanced panel for that? I have read though the forum but haven't able to find an answer for my question.
Thanks in advance!
Thank you for your replay. Your code worked perfectly.
Now I've got a new question regarding the structure of my data. I have 11 firms, 7 variables, 29 firmquarters. However, only 3 variables contain 11 crosssectional data (11 series in one company), the other 4 only have timeseries data(one series in one company) . Therefore, this cannot be structured as panel or pool and will lead to "Near singular matrix ". Should I create an unbalanced panel for that? I have read though the forum but haven't able to find an answer for my question.
Thanks in advance!

 EViews Developer
 Posts: 161
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Estimating standard deviation of residuals by using Loop
Let me rephrase your description of your data to see if I understand you correctly. For 3 of your variables you have data for all 11 firms, but you also have 4 additional variables that each apply to 1 firm only? In other words, there are 7 firms for which you have 3 variables and 4 firms for which you have 4 variables?
Re: Estimating standard deviation of residuals by using Loop
Hi Matt,
Thank you for your reply and sorry for misunderstanding.
I have 11 firms, 7 variables, 29 firmquarters. Among these 7 variables:
1) 3 of them I considered as firmspecific proxy,these 3 variables have 11 series for each firms such as returns,dividend, residuals standard deviation.
2) other 4 variables for country proxy, but only have one series such as US volatility and UK volatility etc.
My question is that when I want to put them altogether in one pool, these 7 variables don't have same number of series.
Should I consider it as unbalanced panel? Or just analysing it as timeseries data.
Thank you very much!
Thank you for your reply and sorry for misunderstanding.
I have 11 firms, 7 variables, 29 firmquarters. Among these 7 variables:
1) 3 of them I considered as firmspecific proxy,these 3 variables have 11 series for each firms such as returns,dividend, residuals standard deviation.
2) other 4 variables for country proxy, but only have one series such as US volatility and UK volatility etc.
My question is that when I want to put them altogether in one pool, these 7 variables don't have same number of series.
Should I consider it as unbalanced panel? Or just analysing it as timeseries data.
Thank you very much!

 EViews Developer
 Posts: 161
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Estimating standard deviation of residuals by using Loop
Hello,
If you have all 29 quarter observations for all series, it wouldn't be an unbalanced panel. It sounds more like a pooled data. Specifically, the 3 firm variables would be structured by a pool object and the remaining 4 country variables would be what the EViews documentation calls "ordinary series".
If you have all 29 quarter observations for all series, it wouldn't be an unbalanced panel. It sounds more like a pooled data. Specifically, the 3 firm variables would be structured by a pool object and the remaining 4 country variables would be what the EViews documentation calls "ordinary series".
Re: Estimating standard deviation of residuals by using Loop
Hello Matt，
Thank you for your reply!
My regression equation will be something looks like this?
Y? C dividend? Residual? Volatility_us volatility_uk
Which simply add the non pooled variables at the end of the equation?
Thank you in advance!
Thank you for your reply!
My regression equation will be something looks like this?
Y? C dividend? Residual? Volatility_us volatility_uk
Which simply add the non pooled variables at the end of the equation?
Thank you in advance!

 EViews Developer
 Posts: 161
 Joined: Thu Apr 25, 2013 7:48 pm
Re: Estimating standard deviation of residuals by using Loop
Yes, I imagine something like that would work.
Who is online
Users browsing this forum: Google [Bot] and 6 guests