Displaying 20 results from an estimated 1000 matches similar to: "Help on running regression by grouping firms"
2010 Jul 22
4
Drop firms in unbalanced panel if not more than 5 observations in consecutive years for all variables
Dear R-user,
a few weeks ago I consulted the list-serve with a similar question.
However, my task changed a little but sufficiently to get lost again. So
I would appreciate any help on the following issue.
I use the plm package and work with firm-level data in a panel. I would
like to eliminate all firms that do not fulfill the requirement of
having an observation in every variable used for at
2009 Jul 21
1
strange dlply behavior
I'm running R 2.9.1 on winXP, using the library plyr.
Can anyone explain to me what is going wrong in this code? (in particular
see lines marked with ******************) Trying to modify objects in a list
created using dlply seems to corrupt the objects in the list.
> library(plyr)
> d=as.data.frame(cbind(c(1,1,1,2,2,2),c(1,2,3,4,5,6)))
> d
  V1 V2
1  1  1
2  1  2
3  1  3
4  2  4
5 
2011 Feb 08
1
Grouping by factors in R
I'm having a hard time figuring out how to group results by certain 
factors in R.  I have data with the following headings:
[1] "Time"      "Plot"      "LatCat"    "Elevation" "ElevCat"   
"Aspect"    "AspCat"    "Slope"
[9] "SlopeCat"  "Species"   "SizeClass" "Stems"
and
2012 Mar 18
1
Help with dlply, loop and column names
Hi,
I have a dataframe basically like this:
> head(asturias.gen2011[,c(1,4,9:14)])
               municipio total upyd  psoe    pp    iu   fac        tipo
440              Allande  2031 1.44 31.10 39.75  4.01 21.62  1000-10000
443                Aller 12582 1.37 33.30 37.09 15.53 10.35 10000-50000
567               Amieva   805 1.48 32.69 37.36  6.15 20.16       <1000
849              
2010 Jan 22
2
sorted reshaping?
dear R wizards:? I am wrestling with reshape.? I have a long data set
that I want to convert into a wide data set, in which rows are firms
and columns are years.
> summary(rin)
     firm              fyear             sim1
 Min.   :1004.00   Min.   :1964.0   Min.   : -1.00000
 1st Qu.:1010.00   1st Qu.:1979.0   1st Qu.: -0.14334
 Median :1016.00   Median :1986.0   Median :  0.00116
 Mean  
2011 Oct 25
1
regression using GMM for mulltiple groups
Inthe code below  I was trying to to obtain the GMM estimates for CAPM
(REGRESSION) for 36 stocks each have 180 observations,however it only gives
me one output rather than 36.
In SAS i would just put in a *By statement*.  I have a variable TICKER that
categorize them into 36 groups.
*How can I obtain all 36 output instead of just one.*
**
2013 Jan 08
2
plot residuals per factor
Dear R-users,
I want to plot residuals vs fitted for multiple groups with ggplot2.
I try this code, but unsuccessful.
library("plyr")
models<-dlply(dat1,"d",function(df)
mod<-lm(y~x,data=df)
  ggplot(models,aes(.fitted,.resid), color=factor(d))+
  geom_hline(yintercept=0,col="white",size=2)+
  geom_point()+
  geom_smooth(se=F)
-- 
---
Catalin-Constantin ROIBU
2011 Mar 11
1
Generation of random numbers in a function - (Return command)
Dear R helpers
I have following data.frame and for each product_name, I have associated mean and standard deviation. I need to generate 1000 random no.s for each of these products and find the respective mean and standard deviation.
 
My R code is as follows. 
 
library(plyr)
library(reshape2)
 
filtered_new <- data.frame(product_name = c("P1", "P2", "P3",
2012 Sep 12
6
How to append the random no.s for different variables in the same data.frame
Dear R helpers,
(At the outset I sincerely apologize if I have not put forward my following query properly, though I have tried to do so.)
Following is a curtailed part of my R - code where I am trying to generate say 100 random no.s for each of the products under consideration.
library(plyr)
n = 100
my_code = function(product, output_avg, output_stdev)
    {
BUR_mc = rnorm(n, output_avg,
2011 Aug 23
3
Linear Regression with 2 grouping variables
Hi all,
I have a data set that looks a bit like this.
feed1
      RFU Site Vial Time       lnRFU
1   44448    1    1   10  10.702075
2   47521    1    1   20  10.768927
3   42905    1    1   30  10.66674
4   46867    1    1   40  10.755069
5   42995    1    1   50  10.668839
6   43074    1    1   60  10.670675
7   41195    1    1   70  10.626072
8   47090    1    2   10  10.759816
9   48100    1
2013 Aug 27
1
[plyr] Moving average filter with plyr
Dear all,
I'm stuck with a problem using plyr to process a rather large junk of data. What I'm trying to do is applying a moving average to all the subparts of the dataframe (the example data can be found here https://dl.dropboxusercontent.com/u/2414056/testData.Rdata).
require(plyr)
load("testData.Rdata")
applyfilter<-function(x){
  return(filter(x,rep(1/5, times=5)))
}
2012 Apr 03
1
help in ddply
Hi
I've records like this
df=
x	panel
4	1
93	2
21	3
83	4
75	1
87	2
87	3
78	4
50	1
76	2
86	3
65	4
84	1
40	2
39	3
26	4
i want to create histogram out of it . i want all the mid and count values
for panel wise
my code is 
histoutput = ddply(df,.(df[2]),hist)
i'm not able to get the required result.
please help me
using for loop takes a lot of time if there are more records
-----
Thanks
2009 Mar 04
3
Bug in by() with dates as levels?
Trying to use dates in their R-native form (e.g., POSIXct) rather than
turning them into character strings, I've encountered the following problem.
I create a data frame where one column is dates. Then I use "by()" to do a
calculation on grouped subsets of the data. When I try to extract values
from the result, I get "subscript out of bounds". The example below shows
the
2011 Sep 29
3
For loop for subset - repeating same over and over?
Hello, I am using the following script to run an anova for numerous species
in a table that I have:
SiteSpp <-
2011 Nov 03
2
Take variables in data.frame and create list of matrices
Hi,
I have this sample data below and would like to create a list of matricies.
setseed(1254)
id <- c(1,1,1,1 ,2,2,2)
o <- as.factor(c(1:4, 1, 3, 4))
r <- rep(.5, 7)
v <- rnorm(7)
s <- rnorm(7)
dat <-data.frame(id, o, r, v, s)
dat
#> dat
# id o   r          v          s
# 1  1 0.5  0.7024631  2.0813672
# 1  2 0.5 -0.5541955  0.1095156
# 1  3 0.5 -1.0418167  0.4164930
# 1 
2012 Sep 28
3
Better way of Grouping?
Hello R users,
This is more of a convenience question that I hope others might find useful
if there is a better answer.  I work with large datasets that requires
multiple parsing stages for different analysis.  For example, compare group
3 vs. group 4.  A more complicated comparison would be time B in group 3 of
group L with B in group 4 of group L.  I normally subset each group with
the
2012 Mar 30
3
Adding text for written comments to bottom of graphs
Hello All,
Recently developed the code below for graphing patterns of chemotherapy administration. As someone just starting to use R in their work, I managed to figure out some parts of the code but needed help with others. 
setwd("N:/Regimen Coding/0906/Plots Test")
getwd()
TestData <- structure(list(profile_key = c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 
2, 3, 3, 3, 3, 3), line = c(1, 1,
2010 Aug 09
2
coef(summary) and plyr
Dear all,
I?m having trouble getting a list of regression variables back into a dataframe. 
mydf <- data.frame(x1=rnorm(100), x2=rnorm(100), x3=rnorm(100))
mydf$fac<-factor(sample((0:2),replace=T,100))
 mydf$y<- mydf$x1+0.01+mydf$x2*3-mydf$x3*19+rnorm(100)
dlply(mydf,.(fac),function(df) lm(y~x1+x2+x3,data=df))->dl
here I?d like to use 
ldply(dl,coef(summary)) or something
2012 Aug 28
1
don't print object attributes
Dear all
Suppose the object below:
> require(Hmisc)
> require(plyr)
> x <- dlply(iris, .(Species), describe)
How can I print the object without displaying the attributes? I
inspected ?print and ?print.default with no luck.
> x
$setosa
x[, "Sepal.Length"]
      n missing  unique    Mean     .05     .10     .25     .50     .75
     50       0      15   5.006    4.40    4.59
2011 Aug 29
2
splitting into multiple dataframes and then create a loop to work
Dear All
Sorry for this simple question, I could not solve it by spending days.
My data looks like this:
# data
set.seed(1234)
clvar <- c( rep(1, 10), rep(2, 10), rep(3, 10), rep(4, 10)) # I have 100
level for this factor var;
yvar <-  rnorm(40, 10,6);
var1 <- rnorm(40, 10,4); var2 <- rnorm(40, 10,4); var3 <- rnorm(40, 5, 2);
var4 <- rnorm(40, 10, 3); var5 <- rnorm(40, 15,