Announcement

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

  • Invalid lval

    Hi,

    I am new to mata, and I'm replicating an old code that uses it. Unfortunately, I'm getting the errors `invalid lval r(3000)` after the assignment of elements x, x1, estvcov and estmean (lines 3, 4, 5, 6, 7, 12, 14, 15 of the code below). I understand this error appears when the element is not an lval (https://www.stata.com/manuals13/m-2op_assignment.pdf). However, all of the following items should be matrices, and so I do not understand why this error appears. (Note that simvalues1 and simvalues2 are also matrices).

    Would highly appreciate any help!
    Thanks.


    mata
    function pctChangeCI(x, x1, estmean, estvcov) {
    // x = (st_matrix("simvalues1"), 1)
    // x1 = (st_matrix("simvalues2"), 1)

    //x = (1, st_matrix("simvalues1"))
    //x1 = (1, st_matrix("simvalues2"))


    //estvcov = ( 0.0321425679334, -0.0125258708837030, -0.01224257550358, -0.020567673273258, -0.00081447962364744, 0.001283175119054, -0.00037078276968431) \ (-0.0125258708837, 0.0247147324992786, 0.00572957906882, 0.013578287152935, -0.00021238922227112, -0.000095793687137, 0.00000054591255634) \ (-0.0122425755036, 0.0057295790688211, 0.02474244266765, 0.000709502894560, 0.00038112327914381, -0.000473762169358, 0.00003959881093361) \ (-0.0205676732733, 0.0135782871529354, 0.00070950289456, 0.046983991203950, 0.00015659148543411, 0.000004182942966, -0.00007048925426224) \ (-0.0008144796236, -0.0002123892222711, 0.00038112327914, 0.000156591485434, 0.00010085537196102, -0.000047774418586, 0.00000001528810965)\ ( 0.0012831751191, -0.0000957936871374, -0.00047376216936, 0.000004182942966, -0.00004777441858647, 0.000163152376626, -0.00000408242456036)\ (-0.0003707827697, 0.0000005459125563, 0.00003959881093, -0.000070489254262, 0.00000001528810965, -0.000004082424560, 0.00003239995503067)

    //estmean = (-2.53549625658, 2.43252537821, 4.12186913122, 1.05335147161, 0.04816370328, -0.06482512498, -0.06319703473)


    conflevel = .95
    //estmean = st_matrix("e(b)")
    //estvcov = st_matrix("e(V)")
    probvec = (.5, (1-conflevel)/2, 1-(1-conflevel)/2)

    g_theta = (invlogit(rowsum(x1:*estmean)) - invlogit(rowsum(x:*estmean)))/invlogit(rowsum(x:*estmean))

    dg_theta = (invlogit(rowsum(x:*estmean)) * (x1 * logisticden(rowsum(x1:*estmean)) - (x * logisticden(rowsum(x:*estmean)))) - (invlogit(rowsum(x1:*estmean)) - invlogit(rowsum(x:*estmean))) * x * logisticden(rowsum(x:*estmean))) / (invlogit(rowsum(x:*estmean))^2)

    g_theta_sd = sqrt(dg_theta * estvcov * dg_theta')

    probvec = (invnormal(probvec):*g_theta_sd:+g_theta):*100
    return(probvec)

    }
    end
Working...
X