[R] looping using 'diverse' package measures

Li Jiang lihelenjiang at gmail.com
Thu Oct 19 11:08:10 CEST 2017


Hi everyone,

I'm new at R (although I'm a Stata user for some time and somehow
proficient in it) and I'm trying to use the 'diverse' R package to compute
a few diversity measures on a sample of firms for a period of about 10
years. I was wondering if you can give me some hints on how to best proceed
on using the 'diverse' package.

My sample has the following setup. It's comprised of a annual variable
number of firms which are identified by the companyid variable and the year
variable (unbalanced panel). In addition I also have a variable identifying
the worker, workerid. I then have a set of variables which i want to use as
the basis for calculating some of the measures in the 'diverse' package. An
example of the sample is as follows, using the gender variable (0 for male
and 1 for female) as the variable of interest:

companyid   year    workerid    gender
85390   1999    46446384    0
85390   1999    126800000   1
85390   1999    163300000   0
85390   1999    60225451    0
85390   1999    60195422    0
85390   2000    60225451    0
85390   2000    3571000000  1
85390   2000    163300000   0
85390   2000    163300000   0
85390   2000    126800000   0
85390   2001    60195422    0
85390   2001    60225451    1
85390   2001    46446384    0
85390   2001    60195422    0
85390   2001    60225451    0
4391076 2005    13753759    0
4391076 2005    49988911    0
4391076 2005    112400000   0
4391076 2005    185500000   0
4391076 2005    35649643    0
4391076 2005    65809705    0
4391076 2005    114200000   0
4391076 2005    192100000   0
4391076 2005    64258701    0
4391076 2005    1212000000  1

Based on the 'diverse' need to calculate for each firm, for each year, for
instance the diversity(gender) measure.  in Stata this would be obtained
just a issuing a by firm year command, but have no idea how to tackle this
is issue in R. Any ideas?

Best wishes,

Li

	[[alternative HTML version deleted]]



More information about the R-help mailing list