Announcement

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

  • rowmax returning observation number, not max within row

    Dear all,

    For some reason, when I run this code on my dataset, egen creates a variable containing the observation number of each row instead of the maximum across observations. I just can't seem to figure out what's going on. Thank you in advance!

    Code:
    egen maxv = rowmax(__*)
    sum maxv
    The dataset looks like:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(__BS111400_p __BS111A00_p __BS112500_p maxv)
        .02986717    .002714447             0  1
       .072100684     .06976562 .000021618145  2
     4.318047e-06 .000016268317    .013628376  3
      .0019975295     .02660001     .01942118  4
     .00011598477   .0001928249     .00017276  5
    1.0046353e-10   3.17521e-10     .02495834  6
     .00027324088  .00020779375  .00002767016  7
       .006443177    .012688478    .008952809  8
       .025992706    .003201397     .00483725  9
     .00007730682  .00003245989  .00002056536 10
    end

  • #2
    Xiaoyang:
    actually, it seems that Stata reports the -_n- number.
    You can easily work that around by typing:
    Code:
    egen maxv = rowmax( __BS111400_p __BS111A00_p __BS112500_p )
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      egen uses a temporary variable to keep track of sort order. It is the way that sortpreserve is implemented. It contains the observation identifiers when egen is started.

      In your case therefore the wild card __* catches that. as all temporary variables have the prefix __ (double underscore). You are being bitten by that because your other variables are all fractions less than 1, or so it seems.

      I'd usually avoid variable names starting with that prefix for that reason alone.

      Comment


      • #4
        Dear Carlo and Nick,

        Thank you both so much for the reply! I didn't know that egen uses temporary variables with a double underscore prefix, and as I have too many variables in the form of __* to manually type into the argument of rowmax, changing the variable names fixes the problem. Have a great weekend!

        Comment

        Working...
        X