Announcement

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

  • How to randomly select rows or cols of a matrix in Mata?

    Hi all,

    I would like to find a function like the Matlab function randperm() in Mata, which randomly selects rows of a matrix and reorder these selected rows. sample() or bsample() are for Stata variables. I tried to use rdiscrete() to selecet row indexes first. But the problem is that rdiscrete() would return double indexes. I am wondering whether there is a function in Mata can fulfill this task. Thanks.

  • #2
    You can use Mata function jumble(),which puts the row of matrix in random order. See

    Code:
    help mf_jumble
    for detail and examples.

    Comment


    • #3
      Thank you, Hua. The jumble() is exactly what I need.

      Comment

      Working...
      X