Announcement

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

  • "Loop" list of variables with letters

    I am trying to agregate variables (part of different random experiments) in one unique variable covering all the sample (group A+group B+ group C, etc). I have to do this for a lot of variables, so I was trying to create a "loop". Variables are coded like missing_wave2question1a, missing_wave2question1b, missing_wave3question1c, etc.

    What I want to do is to create a "loop" to perform the same as:
    egen missing_wave3question1= rowtotal(missing_wave2question1a missing_wave2question1b missing_wave2question1c (...)).-> I use egen rowtotal to avoid missings.

    I have tryied to create a macro like:
    local letter a b c (...)
    egen missing_wave3question1= rowtotal(missing_wave2question1`letters') -> do not perform correctly

    or to use :
    egen missing_wave3question1= rowtotal(missing_wave2question1*)-> uses too many variables (10, 11, 12, etc)

    I know that this may be an easy task, but I am stuck. If I can do this then I would be able to crate a larger loop for all the variables with a few lines of code, but I need to solve this "letters issue".

    Thanks!

  • #2
    Code:
    egen missing_wave3question1= rowtotal(missing_wave2question1?).

    Comment


    • #3
      There shouldn't be a terminal period (stop) in code above.

      Comment


      • #4
        Originally posted by Nick Cox View Post
        Code:
        egen missing_wave3question1= rowtotal(missing_wave2question1?).
        Thanks, it works (sorry for such an easy question )

        Comment

        Working...
        X