Announcement

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

  • cell-wise matrix exponentiation

    Hello Community,

    I am trying to figure out a tricky calculation with mata: First, I need to raise a non-integer number. namely 2.71282, to the power of each cell of a vector [1,2]. For illustration purposes, lets say I have a vector with the values 0.5 and 3.5 and now I want Stata to compute 2.71282^0.5 and 2.71282^3.5 and store the results yet again in a new matrix. In reality my vector contains 60 cells; that is why I would love some automatization here. In a second step I am raising each cell of the new vector to the power of 0.5. So both steps somehow resemble each other, however I am failing at both

    I am a stata-beginner and originally inteded to go through the vector with the foreach command but I just don't know how to access the individual cells of the vector.

    I would be extremely grateful if someone could give me a hint!

    Thank a lot and Kind regards,

    Mascha

  • #2
    Hi Mascha,

    What you're looking for requires a combination of ":^", which will perform exponentiation by a vector, and "sqrt()" which, will take the square root for you:

    Code:
    mata:
    
    old_vector = (0.5, 3.5)
    new_vector = sqrt(2.71282:^old_vector)

    Comment


    • #3
      Thank you very much Michael!

      Comment

      Working...
      X