Announcement

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

  • matriz multiplication using specific information of a regression

    Hi.

    I am running a regresssion with 11 independent variables trying to explain the ln of wages. The thing is that I am only interested in 8 of those independent variables for later obatining some counterfactual distributions, .
    The variables I am intered in are: ethnici1 edumo2 edumo3 edufa2 edufa3 female birthreg2 birthreg3. The other 3 variables: period2 period3 id_region_birt_2, are just controls.
    My question is,: how can I modify the following code, in order to just obtain mat v= C*b , where C and b onlyconsider information related to the eight above mentioned variables ?


    regress ln_inglab_hora_dos ethnici1 edumo2 edumo3 edufa2 edufa3 female birthreg2 birthreg3 period2 period3 id_region_birt_2 [iw=FEX_C]

    matrix b= e(b)'
    mat list b


    mat rowname b = b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12
    mat list b
    predict mu

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


    ** Residuales
    gen e= ln_inglab_hora -mu


    sum ethnici1 [iw=FEX_C]
    local ethnici1= `r(mean)'
    sum edumo2 [iw=FEX_C]
    local edumo2= `r(mean)'
    sum edumo3 [iw=FEX_C]
    local edumo3= `r(mean)'
    sum edufa2 [iw=FEX_C]
    local edufa2= `r(mean)'
    sum edufa3 [iw=FEX_C]
    local edufa3= `r(mean)'
    sum female [iw=FEX_C]
    local female= `r(mean)'
    sum birthreg2 [iw=FEX_C]
    local birthreg2 = `r(mean)'
    sum birthreg3 [iw=FEX_C]
    local birthreg3= `r(mean)'
    sum period2 [iw=FEX_C]
    local period2= `r(mean)'
    sum period3 [iw=FEX_C]
    local period3= `r(mean)'
    sum id_region_birt_2 [iw=FEX_C]
    local id_region_birt_2= `r(mean)'




    mat C = (`ethnici1', `edumo2', `edumo3', `edufa2', `edufa3', `female', `birthreg2', `birthreg3', `period2', `period3', `id_region_birt_2', 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] +`birthreg2'*b[7,1] +`birthreg3'*b[8,1] +`period2'*b[9,1] +`period3'*b[10,1] + `id_region_birt_2'*b[11,1] + b[12,1]


    Thanksin advace for any help,



  • #2
    It is not clear what you want because of the lack of a reproducible example. See FAQ Advice #12 on how best to pose your question. In general, to extract a submatrix, see

    Code:
    help matrix extraction
    Code:
    sysuse auto, clear
    regress mpg weight gear foreign headroom disp
    mat l e(b)
    *SELECT COEFFICIENTS ON WEIGHT GEAR FOREIGN
    mat select= e(b)[1, "weight".."foreign"]
    mat l select
    *ADD CONSTANT TERM
    mat select = select, e(b)[1, "_cons"]
    mat l select
    Res.:

    Code:
    . mat l e(b)
    
    e(b)[1,6]
              weight    gear_ratio       foreign      headroom  displacement         _cons
    y1    -.00666742     2.0909006    -2.2485512    -.25861057     .00886625     34.818801
    
    .
    . *SELECT COEFFICIENTS ON WEIGHT GEAR FOREIGN
    
    .
    . mat select= e(b)[1, "weight".."foreign"]
    
    .
    . mat l select
    
    select[1,3]
            weight  gear_ratio     foreign
    y1  -.00666742   2.0909006  -2.2485512
    
    .
    . *ADD CONSTANT TERM
    
    .
    . mat select = select, e(b)[1, "_cons"]
    
    .
    . mat l select
    
    select[1,4]
            weight  gear_ratio     foreign       _cons
    y1  -.00666742   2.0909006  -2.2485512   34.818801
    
    .
    Last edited by Andrew Musau; 13 Jan 2024, 01:37.

    Comment


    • #3
      If you are adding control variables, then you do not want to remove them from your calculations. Instead you want to keep them constant at some sensible value. That is after all what a control variable is supposed to do, keep it constant. If you remove that variable from your calculations, then it is still there, you just fixed the value of that control variable to 0, which may or may not make sense, but even if it does make sense you are better of doing that explicitly rather than hide that fact.
      ​​​​​​
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        Dear Andrew and Maarten,
        tahnks a lot for both replies.

        Andrew, I did what you suggested and it worked. I could store the informtion of the coefficients I wanted. THANK YOU!

        Maarten, thanks for hat clarification. Well, I am running these regressions in order to obtain an inequality of opportunity index, which will be fed with some specific variables information. However, I want to put controls for the cohorts and the periods, due to that I am working on a pseudo panel framework, but I am not really interested in that information appearing or affecting my index. But I understand what you mean. THANK YOU

        Comment

        Working...
        X