Announcement

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

  • Error with b matrix

    Hi!

    I am running this code, and it's giving me an error: *b invalid name

    gen v_eth= `ethnici1'*b[1,1] + edumo2*b[2,1] + edumo3*b[3,1] + edufa2*b[4,1] + edufa3*b[5,1] + female*b[6,1] + desplazado1*b[7,1] + b[8,1]


    I had previously run this code,

    * Regresión

    regress ln_PERCAPITA ethnici1 edumo2 edumo3 edufa2 edufa3 female desplazado1 [iw=FEX_C] if FG==1

    **Construccion inicadormatrix
    matrix b= e(b)'
    mat list b

    mat rowname b = b1 b2 b3 b4 b5 b6 b7 b8
    mat list b
    predict mu

    ** Smoothed distribution
    gen mu_tilde= exp(mu) if FG==1
    label var mu_tilde "Smoothed distribution"
    gen ln_mutilde = ln(mu_tilde)

    **drop mu_tilde
    ** Residuales
    gen e= ln_PERCAPITA-mu if FG==1

    *las comillas en el r(mean) indican que estoy utilizando una variable macro
    sum ethnici1 [iw=FEX_C] if FG==1
    local ethnici1= `r(mean)'
    **sum female [iw=FEX_C] if FG==1
    **local female= `r(mean)'
    sum edumo2 [iw=FEX_C] if FG==1
    local edumo2= `r(mean)'
    sum edumo3 [iw=FEX_C] if FG==1
    local edumo3= `r(mean)'
    sum edufa2 [iw=FEX_C] if FG==1
    local edufa2= `r(mean)'
    sum edufa3 [iw=FEX_C] if FG==1
    local edufa3= `r(mean)'
    sum female [iw=FEX_C] if FG==1
    local female= `r(mean)'
    sum desplazado1 [iw=FEX_C] if FG==1
    local desplazado1= `r(mean)'


    mat C = (`ethnici1', `edumo2', `edumo3', `edufa2', `edufa3', `female', `desplazado1', 1)

    mat list C
    mat v= C*b
    mat list v

    gen v= `ethnici1'*b[1,1] +`edumo2'*b[2,1] +`edumo3'*b[3,1] + `edufa2'*b[4,1] + `edufa3'*b[5,1] + `female'*b[6,1] + `desplazado1'*b[7,1] + b[8,1]


    I don't get what the problem is

  • #2
    I don't see any obvious problem with this code, and if it has run successfully before, that would suggest it is, at least syntactically, correct. But you may be getting an error message because of the way you are running it.

    The -gen v = ...- command that you are getting an error message from uses a number of local macros. Remember that a local macro goes out of scope (i.e. becomes undefined) as soon as the "program" within which it is defined finishes. For these purposes, "program" also refers to any single line or group of lines that are run out of the do-editor. The point is that the code you show must be run without interruption from beginning to end. If you attempt to run it one line at a time, or in chunks, the local macros that get defined will have disappeared by the time you reach that last -gen v = ...- line. Then with those local macros no longer existing, will see this code as -gen v = *b[1,1] + *b[2,1] + *b[3,1] // etc.- and will give precisely the error message you are getting.

    Comment


    • #3
      Thank you Clyde!!!

      Comment

      Working...
      X