t-test table for word document - comparing means of two populations

I would like to compare the job satisfaction of part-time workers in the health industry and the financial industry. Should I do a t-test? How can I do this with R. Can I use stargazer to get a table for a word document?

Variables

IND

  • 12 = Financial industry (339 observations)
  • 17 = Health industry (678 observations)

EMP

  • 2 = Part-time

pv1 (Job satisfaction)
scale from 1 to 5

Hi,

Since the job satisfaction is categorical (scale 1 - 5), you should use a Chi-Square test instead of a t-test. There are a lot of tutorials out there about this, here is one.

If you like to output the results to a Word document, I suggest you write the code in an R Markdown file and knit it to word.That should be easiest.

Hope this helps,
PJ

1 Like

What should I do if I treat job satisfaction as a continuous variable?
Where can I find a code for this scenario?

I would like to expand on pieterjanvc's reply.

Categorical data suggests the data may not be used in arithmetic as in means or SD. If 1=likes very much, and 2=likes somewhat, what does its average represent?

The chi-square test allows us to compare an actual distribution with an expected distribution. I think ibn your case it would be OK to call one of your actual distributions an expected distribution, although perhaps someone with more stats knowledge may need to correct me. I think both distributions should be proportions, as in 25% of the data is in category one, etc.

See https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/chisq.test

I'd like to follow-up even more. A chi-square test tests whether the distribution is different. Since these are ordinal data, I'd suggest a Kruskal Wallis test.

https://stats.idre.ucla.edu/other/mult-pkg/whatstat/

2 Likes

Thanks for all your answers. This is very kind.
I am still a beginner. My professor told me to do a t-test to keep things simple.
I am well aware that a different method would be more appropriate.
How do I have to code a two sample t-test with R with the variable in my question and my csv file?

df <- read.csv(file="C:/myfile.csv")
colnames(df) <- c("x", "y")
t.test(df$x, df$y, alternative = "two.sided", var.equal = FALSE)

Note that there are several two sample t tests. I chose variances equal as false.

How do I have to code this with my variables IND, EMP and pv1?
I wand to compare the job satisfaction (pv1) of part-time workers (EMP=2) of the two industries (IND=12 and IND=17).

My x's are your pv1's for IND=12. My y's are your pv1's for IND=17.

If you are only interested in EMP=2, but you have other values of EMP, then you want to remove these other values from the data that you are t testing. If the EMPs are in a separate column, you could use the subset command to delete them

df <- subset(df, EMP==2)

I would like to compare the job satisfaction of part-time workers in the health industry and the financial industry.
Should I do a t-test?
How can I do this with R. Can I use stargazer to get a table for a word document?

Variables

IND

  • 12 = Financial industry (161 observations)
  • 17 = Health industry (151 observations)

pv1 (Job satisfaction)
scale from 1 to 5 (I treat this as a continuous numerical variable. I know that this is controversial)

data=read.csv("jobsatisfaction.csv",header=T,sep=";")
t.test(data$pv1~data$IND)

Is this code correct. How can I get a t-test table for a word document?

I think you want a comma
t.test(y1,y2)
if you are assuming y1 and y2 are numeric

I have this code for a two sample t-test.

t.test(data$pv1~data$IND)

How can I make a nice t-test table for a word document??
(With means, t-value, p-value, significance, etc.)

this could be a start

t.test(1:10, y = c(7:20)) %>% 
broom::tidy() %>% 
flextable::flextable() %>% 
flextable::colformat_num()

Thanks for your answer. But I don't understand this code at all :frowning:
Moreover I have to change the description into german. Is it possible to change it in a word document?
Maybe with stargazer?

Here is an rmarkdown document that knits to word

---
title: "wordstarg"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

## Including Plots

You can also embed plots, for example:

```{r, results='asis'}
t.test(1:10, y = c(7:20)) %>% 
  broom::tidy() %>% flextable::flextable() %>% flextable::colformat_num(digits=2)
```

Thanks. This looks promising.
How would it look like with my code
t.test(data$pv1~data$IND)
?

Sorry , I dont understand your question