install.packages("wooldridge")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.4'
## (as 'lib' is unspecified)
library(wooldridge)

  # Load the wooldridge package
  library(wooldridge)

# Access BWGHT dataset
data("bwght")

# Total women in the sample
total_women <- nrow(bwght)

# Women who smoked during pregnancy
smokers <- sum(bwght$cigs > 0, na.rm = TRUE)

total_women
## [1] 1388
smokers
## [1] 212
  # Average number of cigarettes smoked per day
  avg_cigarettes <- mean(bwght$cigs, na.rm = TRUE)
avg_cigarettes
## [1] 2.087176
# Average number of cigarettes smoked per day among pregnant women who smoked
pregnant_smokers <- bwght[bwght$cigs > 0, ]
avg_cigs_pregnancy <- mean(pregnant_smokers$cigs, na.rm = TRUE)
avg_cigs_pregnancy
## [1] 13.66509
# Average father's education level
avg_fatheduc <- mean(bwght$fatheduc, na.rm = TRUE)
avg_fatheduc
## [1] 13.18624
# Average family income and standard deviation
avg_faminc <- mean(bwght$faminc, na.rm = TRUE)
std_faminc <- sd(bwght$faminc, na.rm = TRUE)

avg_faminc
## [1] 29.02666
# Access MEAP01 dataset
data("meap01")

# 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
  # Number of schools with a perfect pass rate (math4 == 100)
  perfect_pass_rate_schools <- sum(meap01$math4 == 100, na.rm = TRUE)
total_schools <- nrow(meap01)

# Percentage of schools with a perfect pass rate
percentage_perfect <- (perfect_pass_rate_schools / total_schools) * 100

perfect_pass_rate_schools
## [1] 38
percentage_perfect
## [1] 2.084476
  # Number of schools with math pass rate of exactly 50%
  exact_50_percent <- sum(meap01$math4 == 50, na.rm = TRUE)
exact_50_percent
## [1] 17
# Average pass rate for math and reading
avg_math4 <- mean(meap01$math4, na.rm = TRUE)
avg_read4 <- mean(meap01$read4, na.rm = TRUE)

avg_math4
## [1] 71.909
avg_read4
## [1] 60.06188
# Correlation between math4 and read4
correlation <- cor(meap01$math4, meap01$read4, use = "complete.obs")
correlation
## [1] 0.8427281
# Average and standard deviation of expenditure per pupil (exppp)
avg_exppp <- mean(meap01$exppp, na.rm = TRUE)
std_exppp <- sd(meap01$exppp, na.rm = TRUE)

avg_exppp
## [1] 5194.865
std_exppp
## [1] 1091.89
# School A spends $6,000 and School B spends $5,500 per student
school_A <- 6000
school_B <- 5500

# Percentage difference calculation
percentage_difference <- 100 * (log(school_A) - log(school_B))

percentage_difference
## [1] 8.701138