stata_n: Function to mimic the _n function in Stata

Description Usage Arguments Value Examples

Description

Function to mimic the _n function in Stata

Usage

1
stata_n(df, idvar, counter_name = "n")

Arguments

df

Your dataframe

idvar

A string containing the name of the group variable

counter_name

The name of the counter variable. Defaults to "n".

Value

Your dataframe but with at counter with the name according to counter_name

Examples

1
2
df <- data.frame(id = c("A", "A", "B", "B", "B", "C", "C"), val = rnorm(7))
df <- stata_n(df, "id")

Steensson/valhalla documentation built on May 6, 2019, 5:59 p.m.