Announcement

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

  • looping with -tabi-

    hi ,

    does anyone know how I can loop using the -tabi- command? I have 4 variables (v1 v2 v3 v4) and about a 100 lines of data and wish to execute -tabi x x x x,chi2- across the 4 variables but it is time consuming to do it one line at a time ( >100 lines)

    here is what the data looks like and what I want
    line v1 v2 v3 v4
    1 12 32 56 78
    2
    3
    4
    5
    I would like to run -tabi 12 32 \ 56 78,chi2- for line 1 , and then do that in a loop for all lines.

    I hope this ask is clear.

    any feedback would be appreciated.

    thanks
    Vishal

  • #2
    Code:
    forval i = 1/`=_N' {
       tabi `=v1[`i']' `=v2[`i']' \ `=v3[`i']' `v4[`i']', chi2
    }

    Comment


    • #3
      thanks Mike, I thought it would look something like that!!

      Comment


      • #4
        Originally posted by Mike Lacy View Post
        Code:
        forval i = 1/`=_N' {
        tabi `=v1[`i']' `=v2[`i']' \ `=v3[`i']' `v4[`i']', chi2
        }
        I have the exact same problem but this code doesn't quite work for me. STATA expects an integer after tabi. Do you know how to solve this? Thanks so much!

        Comment


        • #5
          tabi expects integer frequencies or counts as input. You must have something else.

          Comment


          • #6
            Originally posted by Nick Cox View Post
            tabi expects integer frequencies or counts as input. You must have something else.
            So like what Mike wrote above, I tried to use index as well (e.g. tabi v1[1] v2[1] \ v3[1] v4[1]) but the command didn't work. My variables are also lists of integers. Do you know why it didn't work?
            tabi `=v1[`i']' `=v2[`i']' \ `=v3[`i']' `v4[`i']' Thanks so much! I really appreciate your help.

            Comment


            • #7
              The first command doesn''t work because tabi expects integers, not expressions with integer values.


              The second command doesn''t work because your last expression for v4 is of incorrect form. The net result is illegal for tabi.

              Comment

              Working...
              X