[R] Help creating a panel dataset
arun
smartpink111 at yahoo.com
Mon Feb 24 16:19:46 CET 2014
Hi,
Try:
dat <- read.table(text="FIRM 'EBITDA 2012' 'EBITDA 2011' 'ROE 2012' 'ROE 2011'
Microsoft 65654 5654 54% 23%
Apple 436354 57658 66% 34%
Facebook 3255 344575 43% 44%",sep="",header=TRUE,stringsAsFactors=FALSE,check.names=FALSE)
colnames(dat)[grep("EBITDA|ROE",colnames(dat))] <- gsub(" ", "_",colnames(dat)[grep("EBITDA|ROE",colnames(dat))])
res <- reshape(dat,direction="long",idvar="FIRM",timevar="YEAR",varying=colnames(dat)[-1],sep="_")
res$FIRM <- factor(res$FIRM, levels=dat$FIRM)
res[order(res$FIRM),]
# FIRM YEAR EBITDA ROE
#1 Microsoft 2012 65654 54%
#4 Microsoft 2011 5654 23%
#2 Apple 2012 436354 66%
#5 Apple 2011 57658 34%
#3 Facebook 2012 3255 43%
#6 Facebook 2011 344575 44%
A.K.
Hello guys .. I hope someone could give an advice on this.
I have a dataset and have to make a panel regression, but my dataset is like this now
(number are random) :
FIRM EBITDA 2012 EBITDA 2011 .. .. ROE 2012 ROE 2011
Microsoft 65654 5654 54% 23%
Apple 436354 57658 66% 34%
Facebook 3255 344575 43% 44%
.. .. .. .. ..
.. .. ..
.. .. ..
i have to change it like this but i'm a newbie in R and i don't know the commands :
FIRM YEAR EBITDA ROE
Microsoft 2012 65654 54%
Microsoft 2011 5654 23%
Apple 2012 436354 66%
Apple 2011 57658 34%
Facebook 2012 3255 43%
Facebook 2011 344575 44%
..
..
..
Do you think does an easy and fast way to di it exist?
Thank you very much to everyone.
Kind regards
More information about the R-help
mailing list