Announcement

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

  • how to write the loop statement?

    I want to write a loop statement to generate a lot of rowmean? How to write such loop statement? Here is each combination of the variables.
    Specifically, the rowmean of "psychFlex14 psychFlex15 psychFlex16 psychFlex17", the rowmean of "psychFlex14 psychFlex15 psychFlex17 psychFlex20", ...

    Thanks a ton!

    Code:
    Item
    psychFlex14 psychFlex15 psychFlex16 psychFlex17
    psychFlex14 psychFlex15 psychFlex17 psychFlex20
    psychFlex12 psychFlex14 psychFlex15 psychFlex16 psychFlex17
    psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex20
    psychFlex12 psychFlex15 psychFlex16 psychFlex17 psychFlex20
    psychFlex15 psychFlex16 psychFlex17 psychFlex19 psychFlex20
    psychFlex12 psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex20
    psychFlex12 psychFlex13 psychFlex14 psychFlex15 psychFlex16 psychFlex17
    psychFlex12 psychFlex15 psychFlex16 psychFlex17 psychFlex19 psychFlex20
    psychFlex12 psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex18
    psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex19 psychFlex20
    psychFlex13 psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex20
    psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex18 psychFlex20
    psychFlex12 psychFlex14 psychFlex15 psychFlex16 psychFlex17 psychFlex19
    psychFlex12 psychFlex15 psychFlex16 psychFlex17 psychFlex18 psychFlex20
    psychFlex12 psychFlex13 psychFlex14 psychFlex15 psychFlex17 psychFlex20
    psychFlex12 psychFlex13 psychFlex15 psychFlex16 psychFlex17 psychFlex20
    psychFlex12 psychFlex14 psychFlex15 psychFlex17 psychFlex18 psychFlex20
    psychFlex12 psychFlex13 psychFlex14 psychFlex15 psychFlex17 psychFlex18
    psychFlex12 psychFlex13 psychFlex14 psychFlex16 psychFlex17 psychFlex20

  • #2
    help egen

    And you may try this,
    egen havg = rowmean(psy*)

    Comment


    • #3
      Originally posted by Noah Mkasanga View Post
      help egen

      And you may try this,
      egen havg = rowmean(psy*)
      Thanks Noah, I know egen rowmean, I want to know how to write the loop statement rather than the function.

      Comment


      • #4
        There is no obvious pattern in #1; at least I cannot figure it out. Please explain how you create these combinations.

        Comment


        • #5
          Originally posted by daniel klein View Post
          There is no obvious pattern in #1; at least I cannot figure it out. Please explain how you create these combinations.
          I manually create these combinations and want to store these combinations to mata or something. Then I want to extract each combinations using the "for" syntax of mata to run
          Code:
          egen a=rowmean(combination1)
          Can it be possible?
          Thanks!

          Comment


          • #6
            There is a crude way to do this. If you store your varlists in a variable item in observations 1 to 20. You can loop like this

            Code:
            forval i = 1/20 { 
                 local which = item[`i'] 
                 egen rowmean`i' = rowmean(`which')  
                 label var rowmean`i'  "mean of `which'" 
            }

            Comment


            • #7
              Thanks Nick! However, the variable "item" is stored in a different data frame or dataset, can the function of "mata" or "frame" realize this?

              Comment


              • #8
                Well, the values of item need to be visible to the other dataset. There are various ways of doing it, but as implied copying and pasting into the main dataset is crude but will get the job done.

                The natural question is why you put information needed for one analysis in a different dataset; the problem seems to be self-inflicted!

                Comment

                Working...
                X