Announcement

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

  • I cant work out how to combine two variables

    Hi, any help would be appreciated.

    I have 2 variables i_health and i_scsf2a, health asks respondents if they have a long standing illness or not and scsf2a asks if there Health condition is limited or not. All respondents where asked both of these questions and I want to create a categorical variable that combines these two and will show to total frequency of respondents that have:
    • No illness
    • Non-limiting long-standing illness
    • Limiting long-standing illness
    I cant workout what code to use to correctly combine these two variables.

    Thank you for your time.

    Click image for larger version

Name:	ghgh.JPG
Views:	1
Size:	32.5 KB
ID:	1641348
    Click image for larger version

Name:	Capture.JPG
Views:	1
Size:	39.9 KB
ID:	1641349
    Last edited by Malik Felton; 17 Dec 2021, 07:34.

  • #2
    Malik:
    welcome to this forum.
    See the -group- functon available from -egen- (or provide interested listers with more details/excerpt, as per FAQ, that aslo discourage, and for very sound reasons, posting screenshots. Thanks).
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      What will happen to those in the new variable if the conditions are not met? See below the code for the combined variable where cases are defined missing if conditions are not met. Also i_scsf2a = 1 and 2 are considered into same category:

      Code:
      g combvar = cond(i_health==2, 1, cond(i_scsf2a==3,2, cond(i_scsf2a==1,3, cond(i_scsf2a==2,3,.))))
      lab define combv 1 "No illness" 2 "Non-limiting long standing illness" 3 "Limiting long standing illness"
      lab val combvar combv
      tab combvar
      Roman

      Comment


      • #4
        The title might attract interest from people with quite different specific questions. In the spirit of the title I mention https://www.stata-journal.com/articl...article=dm0034 as, in effect, an extension of #2 from Carlo Lazzaro

        Comment


        • #5
          Thank you everyone!

          Comment

          Working...
          X