Re: [R] fixed, random effects with variable weights

From: Spencer Graves <spencer.graves_at_pdf.com>
Date: Thu 01 Dec 2005 - 12:41:35 EST

          I don't have STATA and your example is not sufficiently complete for me to replicate anything. However, my approach to that kind of thing is to try to find the absolute simplest possible example I can think and work with that. I have on occasion programmed such simple examples in Excel; if I get the same answers from Excel and R, I have reasonable confidence that I know that R (or STATA) is doing.

          Beyond that, you have a great advantage with R in that the source code is available: To see the R source, type the name of the function at a command prompt. If I do that with "lme", I get the following:

 > lme
function (fixed, data = sys.frame(sys.parent()), random, correlation = NULL,

     weights = NULL, subset, method = c("REML", "ML"), na.action = na.fail,
     control = list(), contrasts = NULL)
UseMethod("lme")

          This is not too helpful by itself. To get further, I use "methods":

 > methods("lme")
[1] lme.formula lme.groupedData* lme.lmList

          Your "fixed" argument appears to have class "formula". In that case, "lme.formula" is the function you want. Typing this at a command prompt gives you the code. You can then copy that into a script file, print it out, and walk through it line by line to make sure you understand what it does. A walk-through like this can be facilitated by using "degug", which you can invoke as follows:

debug(lme.formula)
regsc<-lme(dsc~dcomp+dperc,random=~1|ind7090)

          The "debug" documentation describes how to use it to walk line by line through the function flagged for debugging. You can query the status of any variable at any point, change variables, etc.

	  Hope this helps.
	  spencer graves

Raphael Schoenle wrote:

> Hi everyone,
>
>
> I have tried to solve a simple problem for days but I can't figure out
> how to run it properly. If someone could give me a hint, this would be
> really great.
>
> Basically, I want to run a standard economist's fixed, and random
> effects regression (corresponds to xtreg in STATA) but with _variable_
> weights (they correspond to changing industry shares in the market).
>
> Here is what I do:
>
> regsc<-lme(dsc~dcomp+dperc,random=~1|ind7090)
> update(regsc,weights=varFixed(~wt))
>
> 1. however, my results are different from what I obtain in Stata using
> areg (the weighted fixed effects times series regression). any ideas?
> 2. how do I read of the random affects results from this regression?
> (i.e. coefficients on dcomp and dperc?)
>
> Any hint would greatly be appreciated.
>
> Best,
>
> -Raphael
> [[alternative text/enriched version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves@pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Thu Dec 01 12:47:01 2005

This archive was generated by hypermail 2.1.8 : Thu 01 Dec 2005 - 17:25:18 EST