Learn R Programming

BMisc

BMisc includes miscellaneous functions for working with panel data, quantiles, dealing with formulas, among other things.

Installation

You can install BMisc from github with:

# install.packages("devtools")
devtools::install_github("bcallaway11/BMisc")

or from CRAN with:

install.packages("BMisc")

Example 1: Working with distribution functions

The make_dist creates a distribution function from a vector of value of the random variable and the corresponding value of its cdf.

library(BMisc)
y <- rnorm(100)
y <- y[order(y)]
u <- runif(100)
u <- u[order(u)]
F <- make_dist(y, u)
class(F)
#> [1] "ecdf"     "stepfun"  "function"
# plot(F)

Example 2: Working with panel data

Another useful function is the make_balanced_panel function which drops observations from a panel dataset which are not available in all time periods.

id <- rep(seq(1, 100, 1), 2) ## individual ids for setting up a two period panel
t <- rep(seq(1, 2), 100) ## time periods
y <- rnorm(200) ## outcomes
dta <- data.frame(id = id, t = t, y = y) ## make into data frame
dta <- dta[-7, ] ## drop the 7th row from the dataset (which creates an unbalanced panel)
nrow(dta)
#> [1] 199
dta <- make_balanced_panel(dta, idname = "id", tname = "t")
nrow(dta) ## now all the observations with missing data in any period are dropped
#> [1] 198

Copy Link

Version

Install

install.packages('BMisc')

Monthly Downloads

4,442

Version

1.4.8

License

GPL-2

Maintainer

Brantly Callaway

Last Published

February 4th, 2025

Functions in BMisc (1.4.8)

element_wise_mult

element_wise_mult
get_Yi1

get_Yi1
getWeightedQuantiles

getWeightedQuantiles
get_Yibar_pre

get_Yibar_pre
cs2panel

Cross Section to Panel
get_Yibar_inner

get_Yibar_inner
dropCovFromFormla

dropCovFromFormla
get_YiGmin1

get_YiGmin1
get_Yibar_pre_inner

get_Yibar_pre_inner
get_Yi1_inner

get_Yi1_inner
invertEcdf

invertEcdf
combine_ecdfs

Combine Two Distribution Functions
ids2rownum

Convert Vector of ids into Vector of Row Numbers
make_balanced_panel

Balance a Panel Data Set
get_list_element

Return Particular Element from Each Element in a List
get_Yit

get_Yit
rhs_vars

Right-hand Side Variables
compareBinary

compareBinary
makeDist

makeDist
get_lagYi

get_lagYi
mv_mult

Matrix-Vector Multiplication
orig2t

orig2t
get_first_difference

get_first_difference
rhs.vars

rhs.vars
get_Yit_inner

get_Yit_inner
make_dist

Make a Distribution Function
invert_ecdf

Invert Ecdf
weighted_mean

Weighted Mean
weighted_ecdf

Weighted Distribution Function
weighted_combine_list

weighted_combine_list
get_YiGmin1_inner

get_YiGmin1_inner
weighted_quantile

weighted_quantile
time_invariant_to_panel

time_invariant_to_panel
toformula

Variable Names to Formula
get_Yibar

get_Yibar
get_principal_components

get_principal_components
orig2t_inner

orig2t_inner
lhs.vars

lhs.vars
id2rownum

Take particular id and convert to row number
multiplier_bootstrap

multiplier_bootstrap
panel2cs2

Panel Data to Repeated Cross Sections
weighted_quantile_inner

Quantile of a Weighted Check Function
panel2cs

Panel Data to Repeated Cross Sections
weighted_checkfun

Weighted Check Function
weighted.checkfun

weighted.checkfun
rhs

Right-hand Side of Formula
t2orig

t2orig
getWeightedDf

getWeightedDf
drop_cov_from_formula

Drop a Covariate from a Formula
getWeightedMean

getWeightedMean
t2orig_inner

t2orig_inner
source_all

source_all
get_group_inner

get_group_inner
lhs_vars

Left-hand Side Variables
get_group

get_group
makeBalancedPanel

makeBalancedPanel
subsample

Subsample of Observations from Panel Data
combineDfs

combineDfs
add_cov_to_formula

Add a Covariate to a Formula
BMisc

BMisc
checkfun

Check Function
addCovToFormla

addCovToFormla
TorF

TorF
check_staggered

check_staggered
block_boot_sample

Block Bootstrap
compare_binary

Compare Variables across Groups
compare_binary_inner

Compare a single variable across two groups
getListElement

getListElement
blockBootSample

blockBootSample
check_staggered_inner

check_staggered_inner
drop_collinear

drop_collinear