##BWGHT Dataset
install.packages("wooldridge")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(wooldridge)
#1.How many women are in the sample, and how many report smoking during pregnancy?
num_women <- nrow(bwght)
num_smokers <- sum(bwght$smoke == 1, na.rm = TRUE)
num_women
## [1] 1388
num_smokers
## [1] 0
#2.What is the average number of cigarettes smoked per day?
avg_cigs <- mean(bwght$cigs, na.rm = TRUE)
avg_cigs
## [1] 2.087176
median_cigs <- median(bwght$cigs, na.rm = TRUE)
avg_cigs
## [1] 2.087176
median_cigs
## [1] 0
#3.Among women who smoked during pregnancy, what is the average number of cigarettes smoked per day?
smokers_data <- subset(bwght, smoke == 1)
avg_cigs_smokers <- mean(smokers_data$cigs, na.rm = TRUE)
avg_cigs_smokers
## [1] NaN
#4.Find the average of fatheduc in the sample.
avg_fatheduc <- mean(bwght$fatheduc, na.rm = TRUE)
valid_obs_fatheduc <- sum(!is.na(bwght$fatheduc))
avg_fatheduc
## [1] 13.18624
valid_obs_fatheduc
## [1] 1192
#5.Report the average family income and its standard # Average family income
avg_faminc <- mean(bwght$faminc, na.rm = TRUE)
sd_faminc <- sd(bwght$faminc, na.rm = TRUE)
avg_faminc
## [1] 29.02666
sd_faminc
## [1] 18.73928
##MEAP01 Dataset #1.Find the largest and smallest values of math4.
max_math4 <- max(meap01$math4, na.rm = TRUE)
min_math4 <- min(meap01$math4, na.rm = TRUE)
max_math4
## [1] 100
min_math4
## [1] 0
#2.How many schools have a perfect pass rate on the math test?
num_perfect_pass <- sum(meap01$math4 == 100, na.rm = TRUE)
percentage_perfect_pass <- (num_perfect_pass / nrow(meap01)) * 100
num_perfect_pass
## [1] 38
percentage_perfect_pass
## [1] 2.084476
#3.How many schools have math pass rates of exactly 50%?
num_50_percent_pass <- sum(meap01$math4 == 50, na.rm = TRUE)
num_50_percent_pass
## [1] 17
#4.Compare the average pass rates for math and reading.
avg_math_pass <- mean(meap01$math4, na.rm = TRUE)
avg_read_pass <- mean(meap01$read4, na.rm = TRUE)
avg_math_pass
## [1] 71.909
avg_read_pass
## [1] 60.06188
#5.Find the correlation between math4 and read4.
correlation <- cor(meap01$math4, meap01$read4, use = "complete.obs")
correlation
## [1] 0.8427281
#6.Calculate the average of exppp along with its standard deviation.
avg_exppp <- mean(meap01$exppp, na.rm = TRUE)
sd_exppp <- sd(meap01$exppp, na.rm = TRUE)
avg_exppp
## [1] 5194.865
sd_exppp
## [1] 1091.89
#7.Calculate the percentage difference in spending between two schools.
school_A <- 6000
school_B <- 5500
percent_diff <- ((school_A - school_B) / school_B) * 100
log_diff <- 100 * (log(school_A) - log(school_B))
percent_diff
## [1] 9.090909
log_diff
## [1] 8.701138