R/calculate_SE_data_from_DTA.R
calculate_SE_data_from_DTA.RdThis function reads a DHS dataset, constructs a survey design object, computes weighted estimates of modern contraceptive method sources by sector category, and exports both the proportion matrix and the variance-covariance matrix to Excel files.
calculate_SE_data_from_DTA(filepath, myresultsfolder)A list with two elements (returned invisibly):
Data frame of weighted estimates with counts
Variance–covariance matrix tibble
Output files are written to disk as a side effect.
The function:
Reads DHS survey microdata.
Constructs derived variables such as modern method, sector, and method source.
Builds a survey design using survey.
Computes weighted proportions using svyby().
Extracts the associated variance–covariance matrix.
Exports both datasets as Excel workbooks.
if (FALSE) { # \dontrun{
calculate_SE_data("data/country.dta", "results/")
} # }