Hey Peter,

it is not necessary to use "factor(town)". I can just use "town" as the name of the towns is already numeric.



Am 14.05.2017 um 20:24 schrieb peter dalgaard:
On 14 May 2017, at 10:22 , Tobias Christoph <s3toc...@uni-bayreuth.de> wrote:

Hey David,

when I used your suggested formula: plm( log(revenue) ~ log(supply) + 
factor(town) + as.numeric(as.character(year)), data=R_Test_log_Neu) I will get 
the same results as without considering town and year in the formula. So this 
might not the clue for taking into account a linear trend.
You probably still want a "*" in the model formula.

(It is not obvious to me why a plain factor(town)*year term does not work, 
something in the panel data frame setup auto-converts it to a factor? But why 
do you need to say factor(town) then?)

-pd

Please find attached the results of str(R_Test_log_Neu):
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 132 obs. of 4 variables:
  $ town   : num  1 1 1 1 1 1 1 1 1 1 ...
  $ year   : num  1 2 3 4 5 6 7 8 9 10 ...
  $ revenue: num  39.9 43.3 44 43.2 39.1 ...
  $ supply : num  1 1 1 1 1 1 35 101 181 323 ...



Hope this is helpful.

Toby



Am 13.05.2017 um 16:40 schrieb David Winsemius:
On May 13, 2017, at 4:07 AM, Tobias Christoph <s3toc...@uni-bayreuth.de>
  wrote:

Hey Peter,

thank you. Yes, I want to have "year" in the varibale.
But if I use "*town*year*" as a furmula, R will create new factor
variable with n levels, where n = (num of towns) x (num of years). What
I'm trying to do is create 50 (town x year) variables such that
town1xyear is 1,2,3... when town== 1 and zero otherwise, repeat for
town2xyear, where state == 2, etc.

It is now clear? Sorry for my bad explanations.

I had suggested that you must provide str(R_Test_log_Neu). I'm still suggesting 
this would be a good idea.

Since you have not done so, we can only guess at the right course to follow 
from your reports of problems and errors. Peter pointed out that the `time` 
function was in the 'stats' package (not from plm or elsewhere as I imagined). 
You are implying that 'year' is currently a factor value with levels that 
appears as the character versions of integers.

You may be able to get closer to what is possible by using:

plm( log(revenue) ~ log(supply) + factor(town) + as.numeric(as.character(year)),
      data=R_Test_log_Neu)

This should fix the problem noted by Peter and avoid the potentially incorrect 
construction of the desired linear trend.

If you used the interaction operator "*" between 'town' and the numeric version 
of 'year' it will give you two sets of coefficients involving 'town'. The first set will 
be the mean deviations from the base factor level. The other set will be the differences 
in slopes for the time trends for each of the (factored) towns from the overall time 
trend/slope. And for your data you wouldbe constructing a saturated model ... as you 
observed in your first message (which remains in the copied thread below).



______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to