# Re: st: Weighted random effects -rfregk-

 From Richard Williams To statalist@hsphsun2.harvard.edu, statalist@hsphsun2.harvard.edu Subject Re: st: Weighted random effects -rfregk- Date Sat, 03 Jun 2006 01:49:32 -0400

```At 11:24 PM 6/2/2006, James J Walters wrote:
```
Although I have never done this before, I was able to use the ASCII editor to make the changes to the rfregk.ado file you suggested. This did resolve the problem and the random effects weighted regression produced the expected results. This however leads me to anoher problem. The predict command is not available with either the -u- or -e- option after this regression. I am specifically intersted in the case by case residuals available after -xtreg-. Any thoughts?
i was just getting ready to send you the file so I am glad I kept reading. Glad you got it to work. Unfortunately, a lot (most?) user written commands provide little or no customized support for the predict command. The simplest option may be to find the necessary formulas and then generate the predicted values yourself.

I should probably stop here and wait for somebody who actually knows something about these programs to chime in...But since they may be taking the weekend off...If you are adventurous, here is an approach that may be totally wrong or at least need some tweaking! i.e. you would want to make sure it was giving you the right answers. Take the following rough code and use it to create a file called predtest.ado. Then save it in c:\personal\ado or some other location where Stata will find it. Here is the code:

program predtest, eclass
rfregk `0' [aw = mvalue], re
matrix b = e(b)
matrix V = e(V)
xtreg `0'
ereturn repost b = b V = V
predict u1, u
predict e1, e
end

The aw = part should be replaced by whatever your weighting var is. Here is how I executed it:

. use "http://www.stata-press.com/data/r9/grunfeld";, clear
. predtest invest kstock

What the program does is run rfregk and saves the e(b) and e(V) matrices. It then runs xtreg (perhaps parameters should be added to make it as comparable as possible to rfregk?) It then replaces the e(b) and e(V) matrices created by xtreg with the matrices that were created by rfregk. Finally it computes the predicted values. Does it do all this correctly? I don't know. I did compare the predictions from my program with those produced by xtregre2, and they correlated very highly (more than .999) so I suspect this is in the ballpark but not perfect.

I would still say that your best alternative is to get Stata 9 so you can use Scott Merryman's program! Or maybe bribe him into converting it so it will work in Stata 8.

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: Richard.A.Williams.5@ND.Edu
WWW (personal): http://www.nd.edu/~rwilliam
WWW (department): http://www.nd.edu/~soc
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/