Announcement

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

  • How to construct a three category variables in STATA from 14 items based on some conditon

    Hello everyone,


    For my PhD project, I am going to create a three category positive mental health (PMH) (Languishing, Moderate, and Flourishing) variable based on the short form of PHM scale developed by Corey Keyes. The scale contains 14 items are measured using 5 point Likert Scale as follows:


    never=0,

    once or twice=1,

    about once a week=2,

    about 2 or 3 times a week=3,

    almost every day=4,

    every day=5


    The condition for creating the three-category PMH variable is

    Flourishing requires a response of “almost every day” or “every day” to 1 or more of the 3 emotional well-being questions (first three items), and to 6 or more of the 11 positive functioning questions.

    Languishing requires a response of “once or twice” or “never” to 1 or more of the 3 emotional well-being questions, and to 6 or more of the 11 positive functioning questions.

    Moderate mental health refers to those who are neither flourishing or languishing.



    I have been searching for the code for constructing this variable using STATA.



    I have found the following code for SPSS. However replicate the count (the blue part) section of the code. I can replicate all the remaining codes:



    count hiaff=mhc1 mhc2 mhc3(4,5).

    count loaff=mhc1 mhc2 mhc3(0,1).

    count hifunc=mhc4 mhc5 mhc6 mhc7 mhc8 mhc9 mhc10 mhc11 mhc12 mhc13 mhc14(4,5).
    count lofunc=mhc4 mhc5 mhc6 mhc7 mhc8 mhc9 mhc10 mhc11 mhc12 mhc13 mhc14(0,1).


    recode hiaff (1,2,3=1) (else=0) into hiaffect.
    recode hifunc (6,7,8,9,10,11=1) (else=0) into hifunct.
    recode loaff (1,2,3=1) (else=0) into loaffect.
    recode lofunc (6,7,8,9,10,11=1) (else=0) into lofunct.

    if hiaffect=1 and hifunct=1 mhc_dx=2.
    if loaffect=1 and lofunct=1 mhc_dx=0.
    if hiaffect=1 and hifunct=0 mhc_dx=1.
    if hiaffect=0 and hifunct=1 mhc_dx=1.
    if loaffect=0 and lofunct=1 mhc_dx=1.
    If loaffect=1 and lofunct=0 mhc_dx=1.

    variable labels mhc_dx 'MHC-SF Three Category Diagnosis of Positive Mental Health'.
    value labels mhc_dx 0 'Languishing' 1 'Moderate' 2 'Flourishing'.



    I am not sure how to replicate the first four line of coding started with count (the blue colored section) in the STATA. I will appreciate if any of you help me out. It will be a great help for my PhD project.



    Thank you in advance



    Iqbal Chowdhury



  • #2
    I am not sure that many experienced Stata users here are also fluent in SPSS. I haven't used SPSS in the current century, so will not try to translate.

    Either way, please visit https://www.statalist.org/forums/help#stata (and in passing https://www.statalist.org/forums/help#spelling) to find how to give a data example here.

    (That scale sounds like a way to discard most of the information in the data.)

    Comment


    • #3
      i would need a clear idea of your data structure before i can help. could you give a data example?

      Comment


      • #4
        As suggested in #2 and #3 having a data example will help provide you better solutions. Here is my approach using a random sample of 50 observations.

        Code:
        clear 
        
        // Creating a sample dataset with 50 observations
        set obs 50
        
        gen response_id = _n
        set seed 238765
        foreach var of numlist 1/14 {
            gen v`var' = runiformint(0, 5)
        }
        
        // Emotional wellbeing question (v1-v3) counts
        // For each responseid find the number of Likert responses that are either 4 or 5 for questions 1 to 3 
        egen ewb_count_4_5 = anycount(v1-v3), values(4, 5)
        
        // For each responseid find the number of Likert responses that are either 0 or 1 for questions 1 to 3 
        egen ewb_count_0_1 = anycount(v1-v3), values(0, 1)
        
        // Positive functioning question (v4-v14) counts
        // For each responseid find the number of Likert responses that are either 4 or 5 for questions 4 to 14 
        egen pf_count_4_5 = anycount(v4-v14), values(4, 5)
        
        // For each responseid find the number of Likert responses that are either 0 or 1 for questions 4 to 14 
        egen pf_count_0_1 = anycount(v4-v14), values(0, 1)
        
        
        // Based on the conditions specified, indicator variables are generated
        gen flourishing = 0
        gen languishing = 0
        gen moderate = 0
        
        replace flourishing = 1 if ewb_count_4_5 >= 1 & pf_count_4_5 >= 6
        replace languishing = 1 if ewb_count_0_1 >= 1 & pf_count_0_1 >= 6
        replace moderate = 1 if flourishing == 0 & languishing == 0
        Please note that without seeing the actual data, it is difficult to provide specific answers. Your data may be different from the above sample dataset, but it should at least give you some idea on Stata code.

        Comment


        • #5
          Navi Reddy's code is very helpful and looks good to me. The last few lines can be simplified to

          Code:
          // Based on the conditions specified, indicator variables are generated
          
          gen flourishing = ewb_count_4_5 >= 1 & pf_count_4_5 >= 6
          
          gen languishing = ewb_count_0_1 >= 1 & pf_count_0_1 >= 6
          
          gen moderate = flourishing == 0 & languishing == 0
          But is it possible that flourishing and languishing can both be 1?
          Last edited by Nick Cox; 18 May 2023, 13:08.

          Comment


          • #6
            Since the original poster indicated they wanted a single variable with 3 categories, I would suggest updating Nick's code with:

            Code:
            gen byte wanted = cond((ewb_count_0_1 >=1 & pf_count_0_1>=6),1,cond((ewb_count_4_5>=1 & pf_count_4_5 >=6),2,0))
            label define wanted 0 Languishing 1 Moderate 2 Flourishing
            label values wanted wanted

            Comment


            • #7
              Nick Cox, thank you for simplifying the code.

              Regarding your question about both flourishing and languishing having a value of 1: I don't think it's possible because only one of the two conditions between pf_count_4_5 >= 6 and pf_count_0_1 >= 6 can be met from the 11 variables.

              Comment


              • #8
                That's good to know. You're naturally quite correct.

                Comment

                Working...
                X