Announcement

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

  • Generate new variables that follow uniform distribution conditional on other variables

    Hi all,

    How can I generate new variables (with name new_a, new_b, new_c, new_d, new_e), that each new variable follows uniform distribution U(x,y), and the x is the minimal value of the original variable, y is the max value of the original variable? For example, new_a follows U(x,y), x is the minimal value of a(12.245115586); y is the max value of a(14.961117462).

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(a b c d f)
    13.336472424 3.6547876887 3.6674377564 6.2780269058 8.1
    12.770520302 3.4139535384 3.5463077098 6.4496124031   9
     14.61777432 3.8405060564 3.7293172095 7.8451882845 8.2
    13.681277261 3.5871028676 3.7009998862  7.187718074 8.5
    14.895449189 3.8255983216 3.8608586399 9.5185995624   7
     12.57323461 3.4462837308   3.47408953 6.0612991766 8.9
    12.827010385 3.4176724062 3.6237328885 8.0327449476 7.9
    12.245115586 3.3389946167 3.5084280734 7.7625570776 8.4
    14.450302454 3.6967572038 3.7449727447 8.3807553026 7.2
    14.961117462 3.8310325427 3.7624601169 6.5605270382 8.4
    end
    Best,
    Jack

  • #2
    Code:
    foreach v of varlist a b c d f {
        summ `v', meanonly
        gen double new_`v' = runiform(`r(min)', `r(max)')
    }
    Note: your variable names include f, but not e.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Code:
      foreach v of varlist a b c d f {
      summ `v', meanonly
      gen double new_`v' = runiform(`r(min)', `r(max)')
      }
      Note: your variable names include f, but not e.
      Hi Clyder, thanks for your explanation! Have a good day!

      Comment

      Working...
      X