Announcement

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

  • Categorising and generating new variables based on Likert Scale variables

    Hello,
    I was hoping someone could help me please.

    I am doing my thesis on Inter-Parental conflict and children's mental health. I am going to investigate the differential effects that Verbal IPC, Physical IPC and Co-occurring IPC has on children's mental health as measured by the Argumentative Relationship Scale which has 5 items
    and 5 responses per item/

    5 item variables Value Labels
    are15a1 = 1 -- Never, 2 --Rarely, 3 -- Sometimes, 4 --Often, 5 --Always (Verbal IPC)
    are15a2 = 1 -- Never, 2 --Rarely, 3 -- Sometimes, 4 --Often, 5 --Always (Verbal IPC)
    are15a3 = 1 -- Never, 2 --Rarely, 3 -- Sometimes, 4 --Often, 5 --Always (Verbal IPC)
    are15a4 = 1 -- Never, 2 --Rarely, 3 -- Sometimes, 4 --Often, 5 --Always (Verbal IPC)
    are15a5 = 1 -- Never, 2 --Rarely, 3 -- Sometimes, 4 --Often, 5 --Always (Physical IPC)

    e.g.,
    are15a1 = How often would you and your partner have disagreements regarding child rearing issues?

    Please note: co-occurring IPC is represented by a response of Rarely - Always on ANY of the first 4 items and Rarely-Always on the last item


    Firstly, I need to establish Verbal IPC, Physical IPC and Co-Occurring IPC variables. But having trouble doing so.

    I type in the below code and it gives me an invalid 'are15a2' error so i remove are15a2 just to see what it does, and it gives me invalid 'are15a2' error

    Could you please help me?

    gen Verbal_IPC = 1 if are15a1 are15a2 are15a3 are15a4 !="1 -- Never" & if are15a5 =="1 -- Never"
    gen Physical_IPC = 2 if are15a1!="1--Never"
    gen Co_IPC = 3 if are15a1 are15a2 are15a3 are15a4 !="1--Never" & if are15a5 !=="1--Never"


    Thank you, really appreciate your help!

  • #2
    So, just to get it right...the new variable Verbal_IPC will include are15a1, are15a2, are15a3, are15a4?

    Comment


    • #3
      If 5 variables each have 5 possible categories, then the number of possible cross-combinations is evidently 5^5 = 3125. .

      What you should know is that

      Code:
      are15a1 are15a2 are15a3 are15a4 !="1--Never"
      is not a way to say in Stata (or in any language???)

      Code:
      are15a1 != "1--Never" & are15a2 != "1--Never" & are15a3 != "1--Never" & are15a4 != "1--Never"
      even if those 4 are string variables. If "1--Never" is as said, a value label, then this would be one way to work. :

      Code:
      are15a1 != 1  & are15a2 != 1 & are15a3 != 1 & are15a4 != 1
      assuming that "1--Never" is the value label corresponding to value 1.

      Comment


      • #4
        Hello Harrison, Yes. The Verbal IPC variable includes a response of Rarely - Always on ANY of the first 4 items (are15a1, are15a2, are15a3, are15a4)

        Comment


        • #5
          Thank you Nick. Yes, "1--Never" is the value label corresponding to value 1. I have copied the value labels below for your reference

          1 -- Never
          2 -- Rarely
          3 -- Sometimes
          4 -- Often
          5 -- Always


          I will try the code you suggested and will let you know how i get on. Thank you

          Comment


          • #6
            There are various tricks here.

            1. Use egen to concatenate. Then

            Code:
            egen area15a = concat(area15a?)
            gives you string variables with values from "11111" to "55555"

            so that your condition that no variables have value 1 is equivalent to

            Code:
            strpos(area15a, "1") == 0
            However, watch out for missing values.

            2. Other egen functions can be useful, including rowmin() rowmax() rowtotal() anycount() anymatch() anyvalue().
            Last edited by Nick Cox; 27 May 2024, 05:53.

            Comment


            • #7
              Hey Nick,

              The below code worked. I just need to put the OR command in, as a reponse of Always - Never on ANY of the first 4 variables (are15a1, are15a2, are15a3, are15a4) represent Verbal IPC..

              gen Verbal_IPC = 1 if are15a1 != 1 & are15a2 != 1 & are15a3 != 1 & are15a4 != 1 & are15a5 == 1

              Do you know how to include the OR | ?

              Comment


              • #8


                Code:
                gen Verbal_IPC = min(are15a1, are15a2, are15a3, are15a4) > 1 & are15a5 == 1
                See also https://journals.sagepub.com/doi/pdf...36867X19830921

                Comment


                • #9
                  Thanks Nick... I'm back with a more complicated question.


                  I have to now determine Verbal ipc If ONLY ONE of the 4 variables are15a1, are15a2, are15a3, are15a4 is "Always or Often"

                  I have dichotomised these 4 variables to Yes 1 or No 0. But i cant figure out the formula to create a new variable if ONE of these four variables are a yes AND are15a5 is 1 (Never)

                  I thought the code you gave me would work but it just gives me 0 which doesn't look right

                  gen VERBAL_ipc = min(Verbal1, Verbal2, Verbal3, Verbal4) > 1 & are15a5 == 1.



                  So, I tried the following:


                  generate verbaladd = Verbal 1 + Verbal 2 + Verbal3 + Verbal 4

                  generate verbaladds = 1 if verbaladd > 1 & verbaladd !=.

                  This gives me a verbaladds variable which has 1 for a Always or Often on ANY of the four variables are15a1, are15a2, are15a3, are15a4

                  So I thought I could easily generate a VerbalIPCfinal variable by coding:

                  generate VerbalIPCfinal = 1 if verbaladds> 1 & verbaladds !=. & are15a5 == 1

                  But it just gives me all .'s


                  where am I going wrong??


                  Can I just change it in Excel and then import excel into STAT ready for the analysis? Would that be an issue if I did this?
                  Last edited by Belcaryn Catanza; 27 May 2024, 22:48.

                  Comment


                  • #10
                    You can always use Excel if you prefer. What issues might there be? I don't use Excel for anything if I can avoid it, but I appreciate that many other people jump the other way. What I prefer, and many other people do so too, is being able to report if asked a complete script that goes all the way from original data to final results. Deciding that it is more convenient to do something in some other software is one thing. Reporting that you couldn't work out how to do it is another thing.

                    I have already given you several hints on useful functions and commands.

                    Your latest want is

                    ONLY ONE of the 4 variables are15a1, are15a2, are15a3, are15a4 is Always or Often AND are15a5 is Never

                    which can be approached like this:

                    Code:
                    egen verbal = anycount(are15a1 are15a2 are15a3 are15a4), values(4 5)
                    replace verbal = verbal == 1 & are15a5 == 1
                    I have some simple tips.

                    1. Sometimes it is evident that you can get there in one line. There is no shame, and much benefit, in breaking a calculation into simple steps. If there is a choice between being clear and seeming clever. go for being clear.

                    2. The Stata Journal paper linked in #8 covers various devices you're not using yet. Using if qualifiers may seem obvious but they aren't always the best tool towards clear and clean code.

                    3. egen is your friend. Did you look at the help to find out about relevant functions?

                    4. Make yourself a sandbox dataset with all 3125 outcomes and check that your indicators give exactly the right results after you've created them.


                    Comment


                    • #11
                      Thanks for all the information Nick and the code, it works and I feel more confident to keep going with Stata.

                      Comment

                      Working...
                      X