Announcement

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

  • Generate multiple variables with loops

    Hello,

    I have the following code:

    g Q1 = aqol1
    g Q2 = aqol2
    g Q3 = aqol3
    g Q4 = aqol4
    g Q5 = aqol5
    g Q6 = aqol6
    g Q7 = aqol7
    g Q8 = aqol8
    g Q9 = aqol9
    g Q10 = aqol10
    g Q11 = aqol11
    g Q12 = aqol12

    ************************************************** ***************
    ********* Imputing Missing Values in Database *********
    ************************************************** **************


    * Dimension 1. Independent Living

    egen IL_miss = rowmean(Q1 Q2 Q3)
    egen ILmissno = rowmiss(Q1 Q2 Q3)

    replace Q1=round(IL_miss) if missing(Q1) & ILmissno==1
    replace Q2=round(IL_miss) if missing(Q2) & ILmissno==1
    replace Q3=round(IL_miss) if missing(Q3) & ILmissno==1



    Following this code (and the rest of it which I didn't post), I will eventually get a single numeric score. My question is...How can I change the code to allow for the fact that Questions 1 through Questions 12 gets measured at multiple different timepoints in which case I would end up with a multiple scores? Is there a looping mechanism that I can use?

    Thanks all,






  • #2
    Sorry - part of the above code should look like this:

    g aqol1 = Q1
    g aqol2 = Q2
    g aqol3 = Q3
    g aqol4 = Q4
    g aqol5 = Q5
    g aqol6 = Q6
    g aqol7 = Q7
    g aqol8 = Q8
    g aqol9 = Q9
    g aqol10 = Q10
    g aqol11 = Q11
    g aqol12 = Q12

    Comment


    • #3
      Anybody have an idea on how to go about this?

      Comment


      • #4
        Sorry to say, I don't really have any idea what you want to accomplish.

        Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post, looking especially at sections 9-12 on how to best pose your question.

        Even the best descriptions of data are no substitute for an actual example of the data. This problem is sufficiently complex that whoever helps you will want to be able to test their code in an example of your data. It would be particularly helpful to post a small hand-made example, showing the data before the process and how you expect it to look after the process. This should include data at more than one timepoint, so we can fully understand what you want to accomplish.

        Please be sure to use the dataex command to show your example data. If you are running version 15.1 or a fully updated version 14.2, it is already part of your official Stata installation. If not, run ssc install dataex to get it. Either way, run help dataex and read the simple instructions for using it. dataex will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

        When asking for help with code, always show example data. When showing example data, always use dataex.

        Comment

        Working...
        X