##Uploading LM Data

library(readxl)
#Load RN Data
LM2024<- read_excel("//hsc-ctscvs6/NMHWA2012/2023 Analysis - 2024 Report/Midwifery Data/LM2024.xlsx")
dim(LM2024)
## [1] 38 72

##Attempt to identify and remove duplicate license numbers

#RN duplicate License Numbers
table(LM2024$'LicenseNo')
## 
##  01417R  02429R   0335R  04008R  08050R  09060R  10078R  11092R  11093R  12098R 
##       1       1       1       1       1       1       1       1       1       1 
##  13113R  13115R  14120R  14130R  16153R  16156R  17163R  17167R  17168R  17170R 
##       1       1       1       1       2       1       1       1       1       1 
##  18181R  18183R  19189R  19191R  19193R  20001R  20004R  20005R  20007R  20008R 
##       1       1       1       1       1       1       1       1       1       1 
##  21006R  22004R 84100-R  89204R  95284R  963O7R  R15151 
##       1       1       1       1       1       1       1
duplicated(LM2024$'LicenseNo')
##  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [25] FALSE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [37] FALSE FALSE
#RN_No_Duplicates<- unique(LM2024$'LicenseNo'`)
#dim(RN_No_Duplicates)

Demographics- Ethnicity

#LM Ethnicity
table(LM2024$Hispanic)
## 
## Decline      No     Yes 
##       2      31       5
LM_counts <- table(LM2024$Hispanic)
LM_total_count <- sum (LM_counts)
LM_percentage_by_group <- (LM_counts / LM_total_count)*100
round(LM_percentage_by_group, 1)
## 
## Decline      No     Yes 
##     5.3    81.6    13.2
barplot(LM_percentage_by_group, main="LM by Ethnicity", xlab="Race", ylab="Percentage")

Demographics- Race

#RN Race
table(LM2024$race1)
## 
## African American          Decline            White 
##                1                2               33
table(LM2024$race2)
## 
##         Decline Native American 
##               1               3
LM_counts_race <- table(LM2024$race1)
LM_total_count_race <- sum (LM_counts_race)
LM_percentage_by_group_race <- (LM_counts_race / LM_total_count_race)*100
round(LM_percentage_by_group_race, 1)
## 
## African American          Decline            White 
##              2.8              5.6             91.7
barplot(LM_percentage_by_group_race, main="LM by Race", xlab="Race", ylab="Percentage")

Demographics- Gender

#RN Gender
table(LM2024$Gender)
## 
## Female   Male 
##     37      1
LM_counts_gender <- table(LM2024$Gender)
LM_total_count_gender <- sum (LM_counts_gender)
LM_percentage_by_group_gender <- (LM_counts_gender / LM_total_count_gender)*100
round(LM_percentage_by_group_gender, 1)
## 
## Female   Male 
##   97.4    2.6
barplot(LM_percentage_by_group_gender, main="LM by Gender", xlab="Gender", ylab="Percentage")

## Demographics- Mean Age

# Turning DOB into age in years
## Download/install necessary R packages
###install.packages("eeptools")
library("eeptools")

##Convert DOB formatting to data class objects
df<-data.frame(LM2024$DateOfBirth)
as.Date(df$DOB, format="m%/%d/%Y")
## Date of length 0
# Turning RN DOB into age in years
date_today <-Sys.Date()
date_today
## [1] "2024-03-25"
start = date_today
end = as.Date(LM2024$DateOfBirth)
LM_Age <- as.numeric(difftime(start, end, unit="weeks"))/52.25

#Calculation of the mean of RN age
LM_age_mean <- mean(LM_Age)
round(LM_age_mean, 1)
## [1] 49.9

Demographics- Counts by NM County

#LM Nurse State/Province counts by county
table(LM2024$`ZipCode2`)
## 
##  Benalillo Bernalillo     Chaves   Dona Ana      Other Rio Arriba   Sandoval 
##          3          3          3          4          9          3          2 
##   Santa Fe       Taos 
##          8          3