Announcement

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

  • IV regression

    Hello and thanks in advance.

    I am trying to run an IV regression for European countries and specific economic sectors. The code is:

    global countries_europe `" "DE" "ES" "FR" "IT" "UK" "' /* European countries */
    global sectors "durman nondurman nonman"
    global util_adj_reg_instruments instrument_oil instrument_fin instrument_uncertainty instrument_mon
    global util_adj_reg_instruments_presurv instrument_oil instrument_fin instrument_uncertainty instrument_mon instrument_oil_presurv instrument_fin_presurv instrument_uncertainty_presurv instrument_mon_presurv
    * Industry dummies by sector
    * European countries
    * Manufacturing
    local inddum_KLEMS_durman_noES "dumC24_C25 dumC26 dumC27 dumC28 dumC29_C30 dumC31_C33"
    local inddum_KLEMS_nondurman_noES "dumC10_C12 dumC13_C15 dumC16_C18 dumC20 dumC21 dumC22_C23"
    foreach c in "DE" "FR" "IT" "UK"{
    global inddum_durman_`c' `inddum_KLEMS_durman_noES'
    global inddum_nondurman_`c' `inddum_KLEMS_nondurman_noES'
    }
    global inddum_durman_ES "dumC24_C25 dumC26_C27 dumC28 dumC29_C30 dumC31_C33"
    global inddum_nondurman_ES "dumC10_C12 dumC13_C15 dumC16_C18 dumC20_C21 dumC22_C23"
    * Non-manufacturing
    local inddum_KLEMS_nonman "dumD dumE dumF dumG dumH dumI dumJ58_J60 dumJ61 dumJ62_J63 dumK dumM_N dumR dumS"
    foreach c in "DE" "ES" "FR" "IT" "UK"{
    global inddum_nonman_`c' `inddum_KLEMS_nonman'
    }

    foreach c of global countries_europe {
    foreach s of global sectors {

    * Run the IV regression
    if "`s'" == "nonman" & "`c'" {
    ivreg2 dZ_unadj_ind (d_capacity_industry = $util_adj_reg_instruments_presurv) ${inddum_`s'_`c'} if country == "`c'" & sector == "`s'" , nocons robust savefirst savefprefix(`c'`s'st1)
    }
    else {
    ivreg2 dZ_unadj_ind (d_capacity_industry = $util_adj_reg_instruments) ${inddum_`s'_`c'} if country == "`c'" & sector == "`s'" , nocons robust savefirst savefprefix(`c'`s'st1)
    }

    predict dZ`c'_`s' if country =="`c'" & sector == "`s'", residual // Extract the residual
    foreach i of global ind_`s'_`c' {
    replace dZ`c'_`s' = dZ`c'_`s' + _b[dum`i'] if country == "`c'" & code == "`i'" // Add back the industry fixed effect
    }
    scalar beta`c'`s' = e(b)[1,1]
    gen aux_coeff_test`s'`c' = beta`c'`s'
    if $replace_neg_beta_0 == 1{
    replace dZ`c'_`s' = dZ_unadj_ind if country =="`c'" & sector == "`s'" & aux_coeff_test`s'`c' < 0
    }
    drop aux_coeff_test`s'`c'

    }
    }

    Even tough i have used this code for a similar analysis, this time Stata returns the error:

    type mismatch
    r(109);

    end of do-file


  • #2
    Where does the code fail? It is not a good strategy to post a lot of code and just report an error, especially if there is no way that we could run your code ourselves.

    Code:
    if "`s'" == "nonman" & "`c'
    will likely fail.

    Code:
    "`s'" == "nonman"
    will be evaluated as true (1) or false (0)

    but

    Code:
    1 & "`c'"
    makes no sense to Stata as a logical expression. The string in "`c'" must be compared with another string, or you need something else.

    There may well be other errors, either before or after that.

    My strategy with similar posts is usually to comment only on the first likely bug I see.

    Comment


    • #3
      The same problem would bite with

      Code:
      0 & "`c'"

      Comment

      Working...
      X