Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to do Mediation Analyses to Subsamples

    Hi Statalist Members,

    I am using the following code to run some mediation analyses (single mediator) to my entire sample. I wondered whether it is possible to do a mediation analysis to a subsample of the same sample in Stata? I am using Stata 17.

    sem (X -> M Y) (M -> Y)

    Thank you.

  • #2
    If you mean you just want to run the analysis restricting it to a subset of the full data set you can either drop the excluded observations from the data set and rerun the same command, or leave the data set alone and ad -if condition_that_defines_the_subsample_you_want- to the -sem- command.

    If you mean that you have a grouping variable that defines 2 or more subsets of the sample and you want to run the mediation analysis in all of those samples, and then perhaps do comparisons across the groups, -sem- also has a -group()- option. There are various ways to use it, holding some or all of the SEM model parameters constant across groups. For details read -help sem_group_options-.

    If you need more specific advice, post back with example data and the exact -sem- model you want to run on it. To show the example data, be sure to use the -dataex- command. In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Hi Clyde, thanks for your help with my question. I will make sure to use the -dataex- next time I ask for help here.

      Comment

      Working...
      X