Data summary table not showing p-value

492 Views Asked by At

I have a data set that looks somewhat like this:

occup <- sample(c("working","housewife"), 100, replace = TRUE) # wife's occupation
age   <- sample(20:60, 100, replace = TRUE) # wife's age
educ  <- sample(0:15, 100, replace = TRUE) # wife's years of education

df <- data.frame(Occupation = occup, Age = age, Education = educ)

The actual data set consists of several variables that could be split into two groups, as per the variable occup. I would like to compare the means (conduct a t-test) of the variables according to their category in occup, in such a way as to obtain a table similar to the one below.

Comparison table

I tried the code below, and it gave me the table below.

library(modelsummary)
datasummary_balance(~occup, data = mydata, output = 'latex')


\begin{table}
\centering
\begin{tabular}[t]{lrrrr}
\toprule
\multicolumn{1}{c}{ } & \multicolumn{2}{c}{housewife (N=8534)} & \multicolumn{2}{c}{working (N=3271)} \\
\cmidrule(l{3pt}r{3pt}){2-3} \cmidrule(l{3pt}r{3pt}){4-5}
  & Mean & Std. Dev. & Mean & Std. Dev.\\
\midrule
age & 43.4 & 12.5 & 44.5 & 11.4\\
educ & 2.1 & 1.5 & 2.0 & 1.7\\
husage & 51.3 & 13.2 & 51.4 & 12.2\\
huseduc & 3.1 & 1.9 & 2.8 & 2.1\\
kids6 & 0.6 & 0.8 & 0.5 & 0.8\\
faminc & 77752.4 & 59414.5 & 80116.5 & 76310.0\\
\bottomrule
\end{tabular}
\end{table}

Second comparison table

But when I add in the command a column for p-value, it gives me the same table as above.

datasummary_balance(~occup, data = mydata, dinm = TRUE, dinm_statistic = "p.value",  output = 'latex')
\begin{table}
\centering
\begin{tabular}[t]{lrrrr}
\toprule
\multicolumn{1}{c}{ } & \multicolumn{2}{c}{housewife (N=8534)} & \multicolumn{2}{c}{working (N=3271)} \\
\cmidrule(l{3pt}r{3pt}){2-3} \cmidrule(l{3pt}r{3pt}){4-5}
  & Mean & Std. Dev. & Mean & Std. Dev.\\
\midrule
age & 43.4 & 12.5 & 44.5 & 11.4\\
educ & 2.1 & 1.5 & 2.0 & 1.7\\
husage & 51.3 & 13.2 & 51.4 & 12.2\\
huseduc & 3.1 & 1.9 & 2.8 & 2.1\\
kids6 & 0.6 & 0.8 & 0.5 & 0.8\\
faminc & 77752.4 & 59414.5 & 80116.5 & 76310.0\\
\bottomrule
\end{tabular}
\end{table}

Can someone please tell what I'm doing wrong? I need to compare the means of the two groups, not only display summary statistics for both groups.

0

There are 0 best solutions below