Learn R Programming

plm (version 0.1-1)

pmean: Conditional mean of a variable

Description

Computes the mean of a variable conditionnaly to the time or the individual index

Usage

pmean(x,cond=NULL,effect="individual",data=NULL)

Arguments

x
a numeric vector or a numeric matrix for which the conditional means should be computed,
cond
a vector containing the conditional variable,
effect
the mean is conditionnal to the individual or the time index whether effect equals "individual" or "time",
data
a pdata.frame.

Value

  • a vector (or matrix) of the same dimension as x containing the conditional means. An attribute "cm" contains a vector (or matrix) containing the conditional means with one line for each value of the conditionnal variable.

Details

If x is a variable of a pdata.frame, pmean(x) finds the "data" attribute of x, extract the individual index from this pdata.frame and computes the individual means. If effect is "time", the time means are computed. The conditional variable may also be explicitely indicated using the cond (a vector of the same length as x) or the data (a pdata.frame) argument. This is the only way to use this function if x is a matrix.

Examples

Run this code
library(Ecdat)
data(Produc)
Produc=pdata.frame(Produc,state,year)
pmean(Produc$pc)
form <- pmean(log(gsp))~pmean(log(pc))
lm(form,data=Produc)

Run the code above in your browser using DataLab