Announcement

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

  • lincom not drawing on values stored in local

    Hi. In running the code below, it runs perfectly until the lincom command, where it fails with the error "w_confirmed_1_1 not found". I'm guessing that the command is not drawing on the values stored in the earlier command "local w_confirmed_1_`i'= 1/_se[treated_post]". I know that the values are generated, as they are displayed after each regression, but I'm not sure why the lincom command is unable to use them. Any help with this will be very greatly appreciated


    Code:
    
    
            use "${outdir}\\1matched_cohort.dta", clear
            
    
            qui sum eventBlock
            local N = r(max)
         
            disp "TOTAL: `N'"
         
         
            * Run regressions    - include test rates 
                
                forvalues i = 1/`N' {
                    disp "`i'"
                    
                  reg confirmed_1 post treated_post tested i.weeknum i.state1 if eventBlock == `i'
                    local w_confirmed_1_`i'= 1/_se[treated_post]  
                    di %4.3f `w_confirmed_1_`i''
                    est sto m_confirmed_1_`i'
                            
                }
        
        
        suest m_confirmed_1*
        
        
                
                local command (scalar(w_confirmed_1_1)*_b[m_confirmed_1_1_mean:treated_post])
                 forval j=2/`N'    {
                disp "`j'"
                local command "`command'  + (scalar(w_confirmed_1_`j')*_b[m_confirmed_1_`j'_mean:treated_post])"        
                }
            
                di "`command'"
                
                lincom `command'
                    
                    
    *****************SAMPLE DATA**************
    
    clear
    input float(confirmed_1 post treated_post tested) byte weeknum long state1 float eventBlock
      .004713926 0 0 .09640159  7 1  6
      .008312343 1 0 1.2649873 11 1 13
      .002806765 0 0 .05048579  6 1  2
      .002626844 0 0         0  5 1  9
        .7967974 1 0  8.805542 26 1 10
      .008312343 1 0         0 10 1 12
       .23389708 1 0  6.429327 22 1  2
        .9619647 1 0  14.64822 30 1  9
      .008780137 1 0  2.461749 14 1  2
       1.1281036 1 0  25.49417 36 1  8
       1.1517812 1 0 27.654156 37 1 13
       1.2512414 1 0  49.57629 45 1  1
       .23389708 1 0  6.429327 22 1  5
     .0024469234 0 0         0  4 1  1
       1.0441525 1 0  19.46225 33 1  7
      .008312343 0 0 .23756747  8 1  3
       1.1746311 1 0  30.29748 38 1  3
       1.1883411 1 0  33.02638 39 1  4
        .4445124 1 0  6.938575 23 1  2
        .3594099 1 0 16.013422 48 1 11
       1.2028787 1 0 35.946453 40 1  3
       1.2028787 1 0 35.946453 40 1  6
      .008312343 1 0  1.872976 12 1  9
      .008312343 0 0         0  9 1  5
       .02400144 1 0  3.956459 17 1  3
       1.2323138 1 0  42.51036 42 1  9
        .9869018 1 0 16.150414 31 1 10
       .02400144 1 0  3.956459 17 1 13
       .03573228 1 0   4.38136 18 1 12
        .9869018 1 0 16.150414 31 1  9
        .9619647 1 0  14.64822 30 1  1
    .00025188917 0 0         0  3 1  1
      .008312343 1 0 2.0354803 13 1  5
      .004713926 1 0 .09640159  7 1 11
      .010759266 1 0  3.002123 15 1  3
      .008780137 1 0  2.461749 14 1  4
      .010759266 1 0  3.002123 15 1  9
      .008312343 0 0         0 10 1  5
        .9619647 1 0  14.64822 30 1  5
       1.1014034 1 0  23.22494 35 1  3
     .0024469234 0 0         0  4 1  8
     .0024469234 0 0         0  4 1 10
      .008312343 0 0         0  9 1  1
       .23389708 1 0  6.429327 22 1  9
      .008312343 1 0         0 10 1 10
      .008312343 1 0 .23756747  8 1 11
      .008312343 0 0  1.872976 12 1  1
        .9005398 1 0  11.85135 28 1  9
       1.2426412 1 0  45.15088 43 1  9
       .04303706 1 0  4.748615 19 1 11
         .013638 1 0  3.484779 16 1  4
       1.1746311 1 0  30.29748 38 1  1
       1.2028787 1 0 35.946453 40 1  4
        .8549838 1 0  10.32965 27 1  2
       .05505577 1 0  5.203814 20 1 12
       1.1517812 1 0 27.654156 37 1  8
      .008312343 0 0         0  9 1  4
        .9005398 1 0  11.85135 28 1  8
    .00025188917 0 0         0  3 1  3
       1.0762144 1 0 21.295826 34 1  8
       1.1281036 1 0  25.49417 36 1  1
       1.1281036 1 0  25.49417 36 1  5
       1.0762144 1 0 21.295826 34 1  5
       1.2512414 1 0  49.57629 45 1  6
     .0024469234 0 0         0  4 1 13
      .004713926 0 0 .09640159  7 1  1
         .013638 1 0  3.484779 16 1 13
       1.0762144 1 0 21.295826 34 1  1
      .010759266 1 0  3.002123 15 1 11
         .013638 0 0  3.484779 16 1  8
       1.2028787 1 0 35.946453 40 1 10
       1.1014034 1 0  23.22494 35 1 11
        .9310543 1 0 13.269522 29 1  6
        .7401943 1 0  7.820691 25 1 11
       1.2471393 1 0  47.19406 44 1 10
      .002626844 1 0         0  5 1 12
        .7401943 1 0  7.820691 25 1  5
       .04303706 0 0  4.748615 19 1  8
        1.256423 1 0  52.06128 46 1  9
    .00025188917 0 0         0  3 1  6
       1.1517812 1 0 27.654156 37 1  4

  • #2
    You are using scalars in the lincom command, so change

    local w_confirmed_1_`i'= 1/_se[treated_post]
    to

    Code:
    scalar w_confirmed_1_`i'= 1/_se[treated_post]

    Comment


    • #3
      Thanks Andrew Musau. That worked perfectly!

      Comment

      Working...
      X