Announcement

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

  • Create a new variable from existing variables with similar value


    Hello,

    First of all i am extremely thankful to everyone whoever is helping with STATA. This forum helped me a lot in learning the software, i am here with a little query.

    I have two variables related to wife and husband response toward a similar question. Well, their response are not similar at large and I needed to create a new variable where both partners have same answers. How i can do that? I am using STATA 15.1.

    PS: Picture of the data is attached.


    Click image for larger version

Name:	Match.png
Views:	1
Size:	7.4 KB
ID:	1521389



  • #2
    You didn't get a quick answer. You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. Pictures and attached files are discouraged - I can't possibly read the picture you attached.

    It depends on whether the family is the observation unit or not. If the husband and wife answers are in the same observation, then a simple generate with
    if husbandresp==wiferesp as a condition would work. Or, a dummy by gen same=(husbandresp==wiferesp).

    If they're not in the same observation (i.e., you have 2 observations per family), you'd sort the data by family and gender, and then you can refer to the other member of the family as

    g x=z if resp=resp[_n+1] & family==family[_n+1]

    You might need to do _n-1 depending on how you sort the data.

    Comment


    • #3
      Thank you so much. It really helped. I have same observations in my data and 'gen' command worked well.

      For next time i will ask questions as per given demonstration.

      Regards,

      Comment

      Working...
      X