Announcement

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

  • Creating a new variable based on two other variables

    The data I am analysing, has a variable with depression scores of a family member and another variable with the relationship of the person (M is Mother, F is Father).

    I need to create a new variable with only the scores for mothers.

    Attached is a sample from the dataset which, includes over 20000 participants.

    I was thinking of something like this..generate mum_EPDS3 = EPDS_Score3 if EPDS3_relation = "M", but it doesn’t work.

    I would appreciate any help you could give me.

    Thanks,
    Karen
    Attached Files
    Last edited by Karen Redhead; 28 Jul 2022, 22:47.

  • #2
    Try

    Code:
    ==
    for testing equality. The first = for assignment is fine.

    However, even


    Code:
    generate mum_EPDS3 = EPDS_Score3 if EPDS3_relation == "M"
    will be wrong if -- as appears -- your variable EPDS3_relation is a numeric variable with value labels then the more direct route is something more like


    Code:
    generate mum_EPDS3 = EPDS_Score3 if EPDS3_relation == 1
    where 1 should be replaced by whatever codes mothers if different.

    Please note our longstanding request not to post MS Word attachments at 12.5 within https://www.statalist.org/forums/help#stata

    One of several reasons why they are deprecated is that they leave key details like that above unclear.
    Last edited by Nick Cox; 29 Jul 2022, 01:54.

    Comment

    Working...
    X