Announcement

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

  • Calculating standard deviation

    Hi all,
    I was hoping to get some guidance on a problem that I'm facing.

    The data that I am working with looks something like this:
    Responses Questions
    1.1(A) 1.1(B) 1.1(C) 1.2(A) 1.2(B) 1.2(C) 2.1(A) 2.1(B)
    Sally 4 5 4 3 18 6 3 2
    Joe 4 6 7 7 7 3 35 3
    Allen 2 7 3 8 5 2 4 8
    I have far more responses(>1000) than those listed here.
    I need to find the standard deviation of all entries to questions ending in (A) for each respondent. So for Sally, I need to find the std dev for the values 4,3,3
    Any ideas on how I can achieve that?

    Thanks!
    Last edited by Sowme Saha; 27 Sep 2018, 15:01.

  • #2
    Hello Sowme. The column headings in your table above are not legal variable names. What are the actual variable names? If the actual variable names end in A, try something like this:

    Code:
    egen sdAvars = rowsd(*A)
    For more info:
    Code:
    help egen
    Then Ctrl-F and search for rowsd.

    HTH.

    p.s. - Remember that Stata is case-sensitive, so a and A are treated differently.
    --
    Bruce Weaver
    Email: [email protected]
    Version: Stata/MP 18.5 (Windows)

    Comment


    • #3
      Thanks Bruce that helps. One followup question -
      suppose I wanted to include all variables ending in A but not 1.2(A) in the std dev calculation, how would I do that?
      Last edited by Sowme Saha; 27 Sep 2018, 17:51.

      Comment


      • #4
        Originally posted by Sowme Saha View Post
        Thanks Bruce that helps. One followup question -
        suppose I wanted to include all variables ending in A but not 1.2(A) in the std dev calculation, how would I do that?
        I don't know a wildcard shortcut for that one. Maybe one of the veteran members of this forum knows one. If not, you'll have to list all of the variables inside the brackets.
        --
        Bruce Weaver
        Email: [email protected]
        Version: Stata/MP 18.5 (Windows)

        Comment


        • #5
          1.2(A) is not a legal variable name in Stata. If you have some number of variables ending in "A" and you want to get the row standard deviation for all of those variable except for a variable with the name var_1_2_a.


          Code:
          unab avars: *a
          local takeout var_1_2_a
          local vlist: list avars - takeout
          egen avar_sd=rowsd(`vlist')
          Stata/MP 14.1 (64-bit x86-64)
          Revision 19 May 2016
          Win 8.1

          Comment


          • #6
            Responses Questions
            time1period1eat time1period1drink time1period1play time1period2eat time1period2drink time1period2play time2period1eat time2period1drink time2period1play
            Sally 4 5 4 3 18 6 3 2 2
            Joe 4 6 7 7 7 3 35 3 6
            Allen 2 7 3 8 5 2 4 8 1
            Please see above variable names.

            Essentially , for each respondent, I need to find the std dev of all variables that contain 'eat' except for the variable 'time2period1eat'.
            Please note that there are more variables than the ones listed here.

            Thanks!
            Last edited by Sowme Saha; 27 Sep 2018, 20:28.

            Comment


            • #7
              In the above code:
              Replace *a with *eat in the first line.
              Replace var_1_2_a with time2period1eat.
              Stata/MP 14.1 (64-bit x86-64)
              Revision 19 May 2016
              Win 8.1

              Comment


              • #8
                Re #5, I was unaware of the -unab- command. Thanks for the pointer, Carole. For others who may not have known about it:

                Code:
                help unab
                --
                Bruce Weaver
                Email: [email protected]
                Version: Stata/MP 18.5 (Windows)

                Comment


                • #9
                  Thanks Bruce and Carole, it works!

                  Comment

                  Working...
                  X