Announcement

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

  • Creating a report using multiple list commands for each observation; forvalues question

    Hi; This is what I think is a very simple forvalues question. I'm trying to create a report listing the values for a number of variables by observation. Unfortunately, 'list' by itself won't work because the total goes over 255 characters (and then some). So, the idea here is, for each observation, list the values of some variables on one line, some on the second line, etc., then move on to the same thing for the next observation.

    This can be accomplished with consecutive list commands restricted by observation as such:
    list var1 var2 if _n==1
    list q1b if index==1


    This is obviously impractical. My idea here was a forvalues loop (I'm embarrassingly inexperienced here) with separate list commands for each set of variables like this;

    local N = _N
    forvalues i = 1/`N' {
    list var1 var2
    list var3 var4
    }

    However, what this gets me is the the output for the first list command for all the observations followed the output of the second list command for all the observations. It looks like this



    If someone could tell me the obvious thing I'm missing here to get the list commands to output consecutively for each observation (or another type of solution to this problem) it would be greatly appreciated.

    (Stata 12)
    Best,
    Jack
    Attached Files

  • #2
    This should be under General. The administrators will move it sooner or later. I guess you are looking for

    Code:
    forvalues i = 1/`=_N' {
         list var1 var2 in `i' 
         list var3 var4 in `i' 
    }
    Being in a loop does not restrict anything to the current observation. Indeed, in this loop, Stata has no idea that there is a current observation at all. But adding in `i' restricts operation as you wish.

    Comment


    • #3
      Thanks, Sorry about the wrong forum, first post and thought I followed all the rules. I thought that would be it, but like I said, new to this, used 'if' instead of 'in'. Thanks again.

      Comment

      Working...
      X