Announcement

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

  • rowmean with varlist

    Hello,

    Based on the syntax for rowmean, I would have thought the following code would run:

    Code:
    egen meanvar=rowmean(var_kappa_calc_* )
    Instead I get the error message:
    variable var_kappa_calc_* not found
    I have many variables with the var_kappa_calc_ prefix and am trying to get the row mean of them all. There are way too many for me to copy and paste manually.

    Does anyone have any suggestions / solutions?

    Thanks

  • #2
    Use dataex to select a sample of the variables as recommended in FAQ Advice #12. The following syntax clearly works

    Code:
    sysuse auto, clear
    rename (price mpg rep78 headroom trunk) (var_kappa_calc_c#), addnumber(1)
    egen meanvar=rowmean(var_kappa_calc_* )

    Comment


    • #3
      rowmean() in egen doesn't have a problem with wildcards:


      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . egen stupid = rowmean(t*)
      
      . ds t*
      trunk  turn
      So, what we need from you is evidence that your wildcard matches your variables by showing us the result of


      Code:
      ds var_kappa_calc_*
      I have to guess at some minor spelling error on your part. A minor error is still an error so far as Stata is concerned, remembering that Stata is case-sensitive too.

      Comment


      • #4
        Thanks both,

        Andrew, I will keep that in mind going forward.

        @Nick,

        Code:
        ds var_kappa_calc_*
        var_ka~c_1_1  var_ka~c_1_2  var_ka~c_1_3  var_ka~c_2_1  var_ka~c_2_2  var_ka~c_2_3  var_ka~c_3_1  var_ka~c_3_2  var_ka~c_3_3
        (Eventually this will cover all pair combinations of 23 unique observations)

        Now, when I entered the command

        Code:
        egen meanvar=rowmean(var_kappa_calc*)
        the means get calculated as I intended.

        For me at least, the issue is resolved since I got the values I needed. But I find it weird that my initial command didn't work since var_kappa_calc_* also appears appropriate.


        Comment


        • #5
          A guess that you may not have typed earlier what you intended may seem disrespectful of your question, but it often happens -- at least many people come back to us not being clear why code didn't work earlier but telling us that the same or similar code works now.

          One reason is that sometimes Stata sees invisible characters that you have picked somehow from other software or typed by accident. Even this forum's software has odd quirks, or that's my story, as sometimes mark-up characters get added (or subtracted) or it decides to translate something into HTML.

          Comment

          Working...
          X