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

C2. Use the data in BWGHT to answer this question.

  1. How many women are in the sample, and how many report smoking during pregnancy?

    # 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
  2. What is the average number of cigarettes smoked per day?

    # Average number of cigarettes smoked per day
    avg_cigarettes <- mean(bwght$cigs, na.rm = TRUE)
    avg_cigarettes
    ## [1] 2.087176
  3. Average number of cigarettes smoked among pregnant women

    # 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
  4. Average of father’s education level (fatheduc)

    # Average father's education level
    avg_fatheduc <- mean(bwght$fatheduc, na.rm = TRUE)
    avg_fatheduc
    ## [1] 13.18624
  5. Average family income and its standard deviation

    # 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
    std_faminc
    ## [1] 18.73928

C3. Analysis for MEAP01 Dataset

  1. Find the largest and smallest values of math4

    # 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
  2. How many schools have a perfect pass rate on the math test?

    # 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
  3. How many schools have a math pass rate of exactly 50%?

    # 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
  4. Compare average pass rates for math and reading scores

    # 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
  5. Find the correlation between math4 and read4

    # Correlation between math4 and read4
    correlation <- cor(meap01$math4, meap01$read4, use = "complete.obs")
    correlation
    ## [1] 0.8427281
  6. Find the average of expenditure per pupil (exppp) and its standard deviation

    # 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
  7. Compare School A and School B’s spending

    # 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