Announcement

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

  • Coding panel data to match respondent choice with CE question

    Hi everyone,

    I am in the process of coding panel data. I have reshaped my data to be long (from wide), so there are 16 rows corresponding to each respondent (4 choice experiments were presented to each respondent with 4 options each). If you see my data in the picture below, you will see the column "CE", which represents which of the 4 options they selected on each choice experiment. I.e., respondent 1 chose option 2 for the first choice experiment and option 3 for the other 3 choice experiments. This is what I need help with -- how do I recode the "CE" variable so that their choice is repeated 4 times for the corresponding question. I.e., respondent 1's CE column would look like 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3. In other words, I want the option they chose for the corresponding question to be repeated four times, aligning next to the same question number. I hope that makes sense.

    Thanks for help.

    Click image for larger version

Name:	Screen Shot 2024-02-23 at 8.56.30 AM.png
Views:	1
Size:	473.7 KB
ID:	1744389

  • #2
    expand 4

    Comment


    • #3
      The expand command just repeats the pattern, correct? I am looking to assign each respondent's first choice to question 1 and the corresponding four options, assign their second choice to question 2 and the corresponding four options, etc. For example, I want the CE variable to be coded as 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 for respondent 1 and 3 3 3 3 2 2 2 2 4 4 4 4 1 1 1 1 for respondent 2.

      Comment


      • #4
        Try this:
        Code:
        capture drop CE2
        g CE2 = .
        forv q = 1/4 {
            bys respondentid: replace CE2 = CE[`q'] if CE_question==`q'
        }

        Comment


        • #5
          This worked perfectly, thanks George!!

          Comment

          Working...
          X