203
MicroEconometria (Código Fuente) Barcelona, juny de 2014 Jordi Arcarons Samuel Calonge

MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria (Código Fuente)

Barcelona, juny de 2014

Jordi Arcarons Samuel Calonge

Page 2: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

1

Attribute VB_Name = "ThisWorkbook"

Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = True Private Sub Workbook_Open() OBRIR = 1 Call C_CREAR(1) End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Call C_ESBORRAR(1) End Sub

Page 3: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

2

Attribute VB_Name = "C0_Credits" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub UserForm_Activate() If Application.Wait(Now + TimeValue("0:00:03")) The n Unload Me End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) Unload Me End Sub

Page 4: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

3

Attribute VB_Name = "C1_Captura" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub Aceptar_Click() Dim avis As Boolean, col As Integer, fil As Integer , i1 As Integer, i2 As Integer, j1 As Integer ERR_LEC = False On Error Resume Next Set R_XY = Range(XY_rang.Text) If Err <> 0 Then ERR_LEC = True Me.Hide MsgBox "La referencia de las variables es incorr ecta.", vbCritical, TITOL Exit Sub End If If X_label.Value Then IX = 1 Else IX = 0 N = R_XY.Rows.Count - IX col = R_XY.Columns(R_XY.Columns.Count).Column fil = R_XY.Rows(R_XY.Rows.Count).Row - N + IX If IX = 1 Then For j1 = 1 To R_XY.Columns.Count If Application.IsNonText(R_XY.Rows(1).Column s(j1)) Then ERR_LEC = True Me.Hide MsgBox "La primera linea no contiene el n ombre de la variable.", vbCritical, TITOL Exit Sub End If Next j1 End If If N - R_XY.Columns.Count <= 5 Then ERR_LEC = True Me.Hide MsgBox "La diferencia entre observaciones y vari ables es 5 o menor, insuficientes grados de liberta d.", vbCritical, TITOL Exit Sub End If If R_XY.Columns.Count > 56 Then ERR_LEC = True Me.Hide MsgBox "Ha seleccionado más de 56 variables.", v bCritical, TITOL Exit Sub End If Set R_XY = Range(Cells(fil + IIf(IX = 0, 1, 0), col - R_XY.Columns.Count + 1), Cells(fil + N - IX, col )) If Application.CountBlank(R_XY) <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de las variables está en bla nco.", vbCritical, TITOL Exit Sub End If ReDim LVAR(R_XY.Columns.Count + 1, 1 To 3) For j1 = 1 To R_XY.Columns.Count If IX = 1 Then LVAR(j1, 1) = Trim(UCase(Cells(fil - 1, j1 + col - R_XY.Columns.Count))) Else LVAR(j1, 1) = "V" & Trim(Str(j1)) End If Next j1 avis = False For Each CTL In Me.Frame3.Controls If CTL.Value Then avis = True TIPUS_ANALISI = CTL.TabIndex + 1 Exit For End If Next CTL If Not avis Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar alguna Opción de Anális is.", vbCritical, TITOL

Page 5: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

4

Exit Sub End If Unload Me End Sub Private Sub Cancelar_Click() SORTIR = True Unload Me End Sub Private Sub Credits_Click() C0_Credits.Show End Sub Private Sub ListBox_fulls_Change() ERR_LEC = False If InStr(1, ListBox_fulls.Value, "_RESULTS", 1) > 0 Then ERR_LEC = True Me.Hide MsgBox ListBox_fulls.Value & " es un nombre rese rvado en MicroEconometría, para las hojas de result ados.", vbCritical, TITOL Exit Sub Else FULL = ListBox_fulls.Value If ActiveSheet.Name <> FULL Then Sheets(FULL).Ac tivate With Me .Aceptar.Enabled = True .Frame2.Enabled = True .XY_rang.Enabled = True .X_label.Enabled = True .Frame3.Enabled = True ' .OptionButton1.Enabled = True For Each CTL In .Frame3.Controls CTL.Enabled = True Next CTL End With End If End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub XY_rang_Enter() Me.XY_rang = "" End Sub

Page 6: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

5

Attribute VB_Name = "C2_Varis" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim height1 As Integer, top1 As Integer Dim ip As Boolean, kp As Integer, lextra() As Strin g, nobsp As Integer, np As Integer, nxp As Integer, _ nyp As Integer, rp As Range, vxp() As Integer Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, j1 As Integer If MultiPage1.Value = 0 Then 'Control impr essió matrius quan k elevat (Regressió) If OPT(0, 0) = 3 Then OPT(3, 3) = c03.Value ElseIf OPT(0, 0) = 5 Then OPT(5, 1) = c01.Value OPT(5, 2) = c02.Value OPT(5, 3) = c03.Value OPT(5, 4) = c04.Value OPT(5, 5) = c05.Value ElseIf OPT(0, 0) = 6 Then OPT(6, 2) = c02.Value ElseIf OPT(0, 0) = 12 Then OPT(13, 2) = c02.Value End If ElseIf MultiPage1.Value = 1 Then 'Predicció ex -post (Regressió i Logit-Probit) ERR_LEC = True If Left(Me.Caption, 10) = "Modelos de" Then For i1 = 1 To kp If ysp4.Selected(i1 - 1) Then ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable endó gena extra-muestral.", vbCritical, TITOL Exit Sub End If nyp = i1 If Application.Count(rp.Columns(nyp)) <> np Then For i1 = 1 To kp ysp4.Selected(i1 - 1) = False xsp4.Selected(i1 - 1) = False obsp4.Selected(i1 - 1) = False Next i1 ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & le xtra(nyp - 1) & " no es numérico.", vbCritical, TIT OL Exit Sub End If End If i2 = 0 For i1 = 1 To kp If xsp4.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve vxp(1 To i2) As Integer vxp(i2) = i1 ERR_LEC = False End If Next i1 If i2 <> k - IC Then ERR_LEC = True If ERR_LEC Then If i2 >= 1 Then For i1 = 1 To kp If Left(Me.Caption, 10) = "Modelos de " Then ysp4.Selected(i1 - 1) = False xsp4.Selected(i1 - 1) = False obsp4.Selected(i1 - 1) = False Next i1 End If Me.Hide MsgBox "Debe seleccionar " & k - IC & " vari able(s) exógena(s) extra-muestral(es).", vbCritical , TITOL Exit Sub End If nxp = i2 If Left(Me.Caption, 10) = "Modelos de" Then For i1 = 1 To nxp

Page 7: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

6

If nyp = vxp(i1) Then ERR_LEC = True Exit For End If Next i1 If ERR_LEC Then For i1 = 1 To kp ysp4.Selected(i1 - 1) = False xsp4.Selected(i1 - 1) = False obsp4.Selected(i1 - 1) = False Next i1 Me.Hide MsgBox lextra(nyp - 1) & " no puede ser e ndógena y exógena extra-muestral.", vbCritical, TIT OL Exit Sub End If End If For i1 = 1 To nxp If Application.Count(rp.Columns(vxp(i1))) < > np Then For i2 = 1 To kp If Left(Me.Caption, 10) = "Modelos d e" Then ysp4.Selected(i2 - 1) = False xsp4.Selected(i2 - 1) = False obsp4.Selected(i2 - 1) = False Next i2 ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & l extra(vxp(i1) - 1) & " no es numérico.", vbCritical , TITOL Exit Sub End If Next i1 ip = False For i1 = 1 To kp If obsp4.Selected(i1 - 1) Then ip = True Exit For End If Next i1 If ip Then nobsp = i1 If Left(Me.Caption, 10) = "Modelos de" Then If nobsp = nyp Then ERR_LEC = True Me.Hide MsgBox lextra(nobsp - 1) & " no puede ser identificador extra-muestral y endógena.", vbCr itical, TITOL Exit Sub End If End If For i1 = 1 To nxp If nobsp = vxp(i1) Then ERR_LEC = True Me.Hide MsgBox lextra(nobsp - 1) & " no puede ser identificador extra-muestral y exógena.", vbCr itical, TITOL Exit Sub End If Next i1 End If ReDim XYp(1 To np, 1 To k + IIf(Left(Me.Caption , 10) = "Modelos de", 1, 0) + IIf(ip, 1, 0)) For i1 = 1 To np If IC = 1 Then XYp(i1, 1) = 1 For j1 = 1 To nxp XYp(i1, IC + j1) = rp.Rows(i1).Columns( vxp(j1)) Next j1 If Left(Me.Caption, 10) = "Modelos de" Then XYp(i1, k + 1) = rp.Rows(i1).Columns(nyp) If ip Then If Left(Me.Caption, 10) = "Modelos de" T hen XYp(i1, k + 2) = rp.Rows(i1).Columns(nobsp) If Left(Me.Caption, 10) <> "Modelos de" Then XYp(i1, k + 1) = rp.Rows(i1).Columns(nobsp) End If Next i1 ElseIf MultiPage1.Value = 2 Then 'Contrastos d 'especificació (Regressió) For i1 = 1 To 9 For Each CTL In Frame7.Controls If CTL.Name = "test7" & i1 Then tests(i 1) = CTL.Value Next CTL Next i1 ElseIf MultiPage1.Value = 3 Then 'Valors de ta ll per al contrast de Chow (Regressió) ERR_LEC = False i2 = 0

Page 8: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

7

For i1 = 1 To 4 For Each CTL In Me.Controls If CTL.Name = "pchow" & i1 Then If CTL.Value <> "" Then If Not IsNumeric(CTL.Value) Or Va l(CTL.Value) <= 0 Or Val(CTL.Value) > N Then ERR_LEC = True Me.Hide MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOK Only, TITOL Exit Sub Else i2 = i2 + 1 ReDim Preserve P_CHOW(1 To i2) P_CHOW(i2) = Val(CTL.Value) End If End If End If Next CTL Next i1 If i2 = 0 Then ERR_LEC = True Me.Hide MsgBox "Debe indicar al menos un punto de co rte.", vbCritical + vbOKOnly, TITOL Exit Sub End If ElseIf MultiPage1.Value = 4 Then 'Variables pe r als contrastos GQ i BP (Regressió) ERR_LEC = False i2 = 0 If Right(Me.Caption, 1) = "t" Then For i1 = 1 To k - IC If ListBox72.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VARS(1 To i2) VARS(i2) = i1 + IC End If Next i1 If i2 = 0 Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar al menos una var iable de la lista.", vbCritical + vbOKOnly, TITOL Exit Sub End If Else If OtrosBP72 Then P_BP = True Else P_BP = Fa lse i2 = 0 i3 = 0 For i1 = 1 To R_XY.Columns.Count If i1 <> NY And i1 <> IY And i1 <> NPES Then i2 = i2 + 1 If ListBox72.Selected(i2 - 1) Then i3 = i3 + 1 ReDim Preserve VARS(1 To i3) VARS(i3) = i1 End If End If Next i1 If i3 = 0 Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar al menos una var iable de la lista.", vbCritical + vbOKOnly, TITOL Exit Sub End If End If ElseIf MultiPage1.Value = 5 Then 'Heteroscedas ticitat (Regressió) '''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' 'Significat de HETEROS() ' 'HETEROS(1)= "MQG" o "MV" (h(1)) 'HETEROS(2)= 1 a 8 (ponderacions), 9=multiplicat iva 'HETEROS(3)= Ajustament (True o False) (Xb) 'HETEROS(4)= Rang (quan és la suma de variables) 'HETEROS(5)= Altres estimacions '''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''' Dim aux As Double, avis As Boolean, cx1 As Strin g, cx2 As String ReDim HETEROS(5) ERR_LEC = False If MQG9 Then

Page 9: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

8

If a91 Then HETEROS(2) = 1 ElseIf a92 Then HETEROS(2) = 2 ElseIf a93 Then HETEROS(2) = 3 ElseIf a94 Then HETEROS(2) = 4 ElseIf a95 Then HETEROS(2) = 5 ElseIf a96 Then HETEROS(2) = 6 ElseIf a97 Then HETEROS(2) = 7 Else HETEROS(2) = 8 End If HETEROS(1) = "MQG" cx1 = IIf(HETEROS(2) = 1 Or HETEROS(2) = 8, " =0", IIf(HETEROS(2) = 4 Or HETEROS(2) = 5, "<=1", " <=0")) cx2 = IIf(HETEROS(2) = 1 Or HETEROS(2) = 8, " es 0.", IIf(HETEROS(2) = 4 Or HETEROS(2) = 5, " es <= 1.", " es <= 0.")) Else HETEROS(1) = "MV" End If i2 = 0 i3 = 0 For i1 = 1 To R_XY.Columns.Count + 1 If i1 <> NY And i1 <> IY Then i2 = i2 + 1 If ListBox92.Selected(i2 - 1) Then i3 = i3 + 1 ReDim Preserve VARS(1 To i3) VARS(i3) = i1 End If End If Next i1 If i3 = 0 Then ERR_LEC = True avis = False Me.Hide MsgBox "Debe seleccionar al menos una de las variables indicadas.", vbCritical, TITOL Exit Sub End If If ListBox92.ListCount = VARS(i3) - 1 - IIf(IY = 0, 0, 1) Then HETEROS(3) = True If i3 > 1 Then ERR_LEC = True avis = False Me.Hide MsgBox "Ajuste(xß), es incompatible con ot ras variables.", vbCritical, TITOL HETEROS(3) = False Exit Sub End If End If If HETEROS(1) = "MQG" Then If UBound(VARS) = 1 Then If Application.CountIf(R_XY.Columns(VARS(1 )), cx1) <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable(" & LVAR(VARS(1), 1) & ")" & cx2, vbCritical, TITOL Exit Sub End If Else Set HETEROS(4) = Cells(F, 30) For i1 = 1 To N aux = 0 For j1 = 1 To UBound(VARS) aux = aux + R_XY.Rows(i1).Columns( VARS(j1)) Next j1 HETEROS(4).Value = aux If Application.CountIf(HETEROS(4), cx1 ) <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la suma de l as variables Z" & cx2, vbCritical, TITOL Exit Sub End If Next i1 HETEROS(4).Clear End If

Page 10: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

9

If HETEROS(3) Then Set HETEROS(4) = Cells(F, 30) For i1 = 1 To N HETEROS(4).Value = YHAT(i1) If Application.CountIf(HETEROS(4), cx1 ) <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor del ajuste(Xß)" & cx2, vbCritical, TITOL Exit For End If Next i1 HETEROS(4).Clear End If End If If OtraHeteros9.Enabled = True Then HETEROS(5) = OtraHeteros9.Value ElseIf MultiPage1.Value = 6 Then 'Autocorrelac ió (Regressió) AUTO(1) = Val(ListBox10.Value) If yw10 Then AUTO(2) = 1 Else AUTO(2) = 2 If AUTO(2) <> 1 Then AUTO(3) = Val(ListBox1021.Value) AUTO(4) = Val(ListBox1022.Value) End If If OtraAuto10.Enabled = True Then AUTO(5) = Otra Auto10.Value ElseIf MultiPage1.Value = 7 Then 'Variables in strumentals ERR_LEC = False For j1 = 1 To UBound(VI_X) avis = True For i1 = 1 To UBound(VI_Z, 1) 'VI_Z es dimensiona a Aceptar11 If VI_Z(i1, j1) <> "" Then avis = False Exit For End If Next i1 If avis Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar al menos un inst rumento para la variable " & VI_X(j1) & ".", vbCrit ical + vbOKOnly, TITOL Exit Sub End If Next j1 If UBound(VI_X) > 1 Then For i1 = 1 To UBound(VI_X) - 1 For i2 = i1 + 1 To UBound(VI_X) For i3 = 1 To UBound(VI_Z, 1) If VI_Z(i3, i1) = "" Then Exit Fo r For i4 = 1 To UBound(VI_Z, 1) If VI_Z(i4, i2) = "" Then Exi t For If VI_Z(i3, i1) = VI_Z(i4, i2 ) Then ERR_LEC = True Me.Hide MsgBox VI_Z(i3, i1) & " no puede ser a la vez variable instrumental de " & _ LVAR(IC + i1, 2) & " y de " & LVAR(IC + i2, 2), vbCritical + vbOKOnly, TITOL For Each CTL In Frame112.C ontrols If TypeName(CTL) = "Li stBox" Then For j1 = 1 To UBoun d(VI_Z, i3) CTL.Selected(j1 - 1) = False Next j1 End If Next CTL Exit Sub End If Next i4 Next i3 Next i2 Next i1 End If ElseIf MultiPage1.Value = 8 Then '"bootstrap" ReDim BOOTSTRAP(1 To 2) If Bootstrap121 Then BOOTSTRAP(1) = True If Bootstrap122 Then BOOTSTRAP(2) = True

Page 11: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

10

End If Unload Me End Sub Private Sub Aceptar4_Click() ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' 'Significat de PREDICS() ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' 'np= Nombre de prediccions 'ip= Identificadors de les prediccions (1=si,0=no) 'fullp= Nom del full de càlcul 'rp= Rang de les prediccions ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' Dim col As Integer, fil As Integer, fullp As String , h As Single, i1 As Integer, i2 As Integer For i1 = 1 To Len(extra_rang4.Text) If Mid(extra_rang4.Text, i1, 1) = "!" Then Exit For Next i1 fullp = Mid(extra_rang4.Text, 1, i1) ERR_LEC = False On Error Resume Next Set rp = Range(extra_rang4.Text) If Err <> 0 Then ERR_LEC = True Me.Hide MsgBox "La referencia de las variables extra-mue strales es incorrecta.", vbCritical, TITOL Exit Sub End If np = rp.Rows.Count - IX kp = rp.Columns.Count col = rp.Columns(kp).Column fil = rp.Rows(np + IX).Row - np + IX If np > 200 Then ERR_LEC = True Me.Hide MsgBox "Ha seleccionado más de 200 predicciones. ", vbCritical, TITOL Exit Sub End If If IX = 1 Then For i2 = 1 To kp If Application.IsNonText(rp.Rows(1).Columns( i2)) Then ERR_LEC = True Me.Hide MsgBox "La primera linea no contiene el n ombre de la variable extra-muestral.", vbCritical, TITOL Exit Sub End If Next i2 End If Set rp = Range(Cells(fil + IIf(IX = 0, 1, 0), col - kp + 1), Cells(fil + np - IX, col)) If Application.CountBlank(rp) <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algunos valores extra-muestrales están e n blanco.", vbCritical, TITOL Exit Sub End If ReDim lextra(kp - 1) For i2 = 1 To kp If IX = 1 Then lextra(i2 - 1) = Trim(UCase(Cells(fil - 1, i 2 + col - kp))) Else lextra(i2 - 1) = "V" & Trim(Str(i2)) End If Next i2 h = Application.min(110, 11 * kp) With Me .Aceptar.Top = h + 60 .Aceptar4.Visible = False .Cancelar.Top = h + 60 .Cancelar4.Visible = False .extra_rang4.Enabled = False .Frame4.Height = h + 50 .Label42.Top = 35 .Label43.Top = 35 .Label44.Top = 35 .MultiPage1.Height = h + 60

Page 12: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

11

.ysp4.Height = h .ysp4.List = lextra .ysp4.Top = 45 .xsp4.Height = h .xsp4.List = lextra .xsp4.Top = 45 .obsp4.Height = h .obsp4.List = lextra .obsp4.Top = 45 If Left(.Caption, 10) <> "Modelos de" Then .Label42.Left = 55 .Label43.Left = 170 .Label44.Visible = False .ysp4.Left = 55 .xsp4.Left = 170 .obsp4.Visible = False End If .Height = h + 105 .Top = top1 - (Me.Height - height1) / 2 End With End Sub Private Sub Aceptar11_Click() Dim h As Single, i0 As Integer, i1 As Integer, i2 A s Integer, i3 As Integer i2 = 0 For i1 = 1 To NX If ListBox111.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VI_X(1 To i2) VI_X(i2) = ListBox111.List(i1 - 1) End If Next i1 ERR_LEC = False If i2 = 0 Or i2 > 5 Then ERR_LEC = True Me.Hide If i2 = 0 Then MsgBox "Debe seleccionar al menos una variable de la lista.", vbCritical + vbOKOnly, TITOL If i2 > 5 Then MsgBox "No puede seleccionar más de 5 variables de la lista.", vbCritical + vbOKOnly , TITOL Exit Sub End If ReDim aux(1 To R_XY.Columns.Count - NX - IY - NPES - 1) As String i2 = 0 For i1 = 1 To R_XY.Columns.Count If IY <> 0 And LVAR(i1, 1) = LVAR(IY, 1) Then G oTo no If LVAR(i1, 1) = LVAR(NY, 1) Then GoTo no If NPES <> 0 And LVAR(i1, 1) = LVAR(NPES, 1) Th en GoTo no For i3 = 1 To NX If LVAR(i1, 1) = LVAR(IC + i3, 2) Then GoTo no Next i3 i2 = i2 + 1 aux(i2) = LVAR(i1, 1) no: Next i1 Dim iv1() As String, iv2() As String, iv3() As Stri ng, iv4() As String, iv5() As String For i0 = 1 To UBound(VI_X) If i0 = 1 Then ReDim iv1(R_XY.Columns.Count - N X - IY - NPES - 2) If i0 = 2 Then ReDim iv2(R_XY.Columns.Count - N X - IY - NPES - 2) If i0 = 3 Then ReDim iv3(R_XY.Columns.Count - N X - IY - NPES - 2) If i0 = 4 Then ReDim iv4(R_XY.Columns.Count - N X - IY - NPES - 2) If i0 = 5 Then ReDim iv5(R_XY.Columns.Count - N X - IY - NPES - 2) i2 = 0 For i1 = 1 To R_XY.Columns.Count For i3 = 1 To UBound(aux) If LVAR(i1, 1) = aux(i3) Then i2 = i2 + 1 If i0 = 1 Then iv1(i2 - 1) = LVAR(i1 , 1) If i0 = 2 Then iv2(i2 - 1) = LVAR(i1 , 1) If i0 = 3 Then iv3(i2 - 1) = LVAR(i1 , 1) If i0 = 4 Then iv4(i2 - 1) = LVAR(i1 , 1) If i0 = 5 Then iv5(i2 - 1) = LVAR(i1 , 1) End If Next i3 Next i1 Next i0 ReDim VI_Z(1 To UBound(aux), 1 To UBound(VI_X))

Page 13: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

12

h = Application.min(70, 11 * (UBound(iv1) + 2)) With Me .Aceptar.Top = h + 65 .Cancelar.Top = h + 65 .Frame111.Visible = False .Frame112.Visible = True .Frame112.Height = h + 30 For i1 = 1 To 5 If UBound(VI_X) >= i1 Then For Each CTL In .Frame112.Controls If CTL.Name = "Frame112" & i1 Then CTL.Caption = VI_X(i1) CTL.Height = h + 10 If i1 = 1 Then CTL.Left = IIf(UBoun d(VI_X) = 1, 160, IIf(UBound(VI_X) = 2, 120, _ IIf(UBoun d(VI_X) = 3, 81, IIf(UBound(VI_X) = 4, 40, 2)))) If i1 = 2 Then CTL.Left = IIf(UBoun d(VI_X) = 2, 199, IIf(UBound(VI_X) = 3, 160, _ IIf(UBoun d(VI_X) = 4, 119, 81))) If i1 = 3 Then CTL.Left = IIf(UBoun d(VI_X) = 3, 239, IIf(UBound(VI_X) = 4, 278, 160)) If i1 = 4 Then CTL.Left = IIf(UBoun d(VI_X) = 4, 200, 239) If i1 = 5 Then CTL.Left = 318 CTL.Visible = True End If If CTL.Name = "ListBox112" & i1 Then CTL.Height = h CTL.List = IIf(i1 = 1, iv1, IIf(i1 = 2, iv2, IIf(i1 = 3, iv3, IIf(i1 = 4, iv4, iv5)))) End If Next CTL End If Next i1 .MultiPage1.Height = h + 60 .Height = h + 110 End With End Sub Private Sub Cancelar_Click() SORTIR = True Unload Me End Sub Private Sub Cancelar4_Click() SORTIR = True Unload Me End Sub Private Sub Cancelar11_Click() SORTIR = True Unload Me End Sub Private Sub ListBox1121_Change() Dim i1 As Integer, avis As Boolean For i1 = 1 To UBound(VI_Z, 1) If ListBox1121.Selected(i1 - 1) Then VI_Z(i1, 1 ) = ListBox1121.List(i1 - 1) Next i1 avis = False For i1 = 1 To UBound(VI_Z, 1) If VI_Z(i1, 1) <> "" Then avis = True Exit For End If Next i1 If avis And UBound(VI_X) > 1 Then ListBox1122.Enabl ed = True End Sub Private Sub ListBox1122_Change() Dim i1 As Integer, avis As Boolean For i1 = 1 To UBound(VI_Z, 1) If ListBox1122.Selected(i1 - 1) Then VI_Z(i1, 2 ) = ListBox1122.List(i1 - 1) Next i1 avis = False For i1 = 1 To UBound(VI_Z, 1) If VI_Z(i1, 2) <> "" Then

Page 14: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

13

avis = True Exit For End If Next i1 If avis And UBound(VI_X) > 2 Then ListBox1123.Enabl ed = True End Sub Private Sub ListBox1123_Change() Dim i1 As Integer, avis As Boolean For i1 = 1 To UBound(VI_Z, 1) If ListBox1123.Selected(i1 - 1) Then VI_Z(i1, 3 ) = ListBox1123.List(i1 - 1) Next i1 avis = False For i1 = 1 To UBound(VI_Z, 1) If VI_Z(i1, 3) <> "" Then avis = True Exit For End If Next i1 If avis And UBound(VI_X) > 3 Then ListBox1124.Enabl ed = True End Sub Private Sub ListBox1124_Change() Dim i1 As Integer, avis As Boolean For i1 = 1 To UBound(VI_Z, 1) If ListBox1124.Selected(i1 - 1) Then VI_Z(i1, 4 ) = ListBox1124.List(i1 - 1) Next i1 avis = False For i1 = 1 To UBound(VI_Z, 1) If VI_Z(i1, 4) <> "" Then avis = True Exit For End If Next i1 If avis And UBound(VI_X) > 4 Then ListBox1125.Enabl ed = True End Sub Private Sub ListBox1125_Change() Dim i1 As Integer, avis As Boolean For i1 = 1 To UBound(VI_Z, 1) If ListBox1125.Selected(i1 - 1) Then VI_Z(i1, 5 ) = ListBox1125.List(i1 - 1) Next i1 End Sub Private Sub MQG9_Click() Dim i1 As Integer If MQG9.Value = True Then With ListBox92 For i1 = 1 To R_XY.Columns.Count .Selected(i1 - 1) = False Next i1 End With Frame93.Visible = True End If End Sub Private Sub MV9_Click() Dim i1 As Integer If MV9.Value = True Then With ListBox92 For i1 = 1 To R_XY.Columns.Count .Selected(i1 - 1) = False Next i1 End With Frame93.Visible = False End If End Sub

Page 15: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

14

Private Sub ListBox10_Change() If ListBox10.Value = 1 Then yw10.Caption = "Prais-Winsten" ywi10.Caption = "Prais-Winsten iterativo" Else yw10.Caption = "Yule-Walker" ywi10.Caption = "Yule-Walker iterativo" End If End Sub Private Sub yw10_Click() If yw10 Then Frame102.Enabled = False For Each CTL In Frame102.Controls CTL.Enabled = False Next CTL ListBox1021.Selected(2) = True ListBox1021.TopIndex = 2 ListBox1022.Selected(25) = True ListBox1022.TopIndex = 25 End If End Sub Private Sub ywi10_Click() If ywi10 Then Frame102.Enabled = True For Each CTL In Frame102.Controls CTL.Enabled = True Next CTL End If End Sub Private Sub UserForm_Activate() height1 = Me.Height top1 = Me.Top End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub

Page 16: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

15

Attribute VB_Name = "C3_Restricciones" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer ERR_LEC = False If Simple Then RESTRICS(k + 2, 2) = 0 If Not Simple Then If Tipus.Visible = True Then RESTRICS(k + 2, 1) = Rest.Value RESTRICS(k + 2, 2) = 1 End If For i1 = 1 To k RESTRICS(i1, 2) = "" For Each CTL In Me.Controls If CTL.Name = "Tb" & i1 Then If Not IsNumeric(CTL.Value) Then ERR_LEC = True Me.Hide MsgBox "La restricción introducida es incorrecta.", vbCritical + vbOKOnly, TITOL Exit Sub Else RESTRICS(i1, 1) = Val(Replace(CTL.Val ue, ",", ".")) RESTRICS(i1, 2) = RESTRICS(i1, 1) End If End If Next CTL Next i1 If Not IsNumeric(Tb_r.Value) Then ERR_LEC = True Me.Hide MsgBox "La restricción introducida es incorrecta .", vbCritical + vbOKOnly, TITOL Exit Sub Else RESTRICS(k + 1, 1) = Val(Replace(Tb_r.Value, "," , ".")) RESTRICS(k + 1, 2) = RESTRICS(k + 1, 1) End If i2 = 0 For i1 = 1 To k If RESTRICS(i1, 1) <> 0 Then i2 = i2 + 1 Next i1 If i2 = 0 Then ERR_LEC = True Me.Hide MsgBox "La restricción introducida es incorrecta .", vbCritical + vbOKOnly, TITOL Exit Sub End If RESTRICS(k + 3, 1) = IIf(Otros.Visible = True, Otro s.Value, False) If Estim.Visible Then RESTRICS(k + 3, 2) = Estim.Va lue Otros.Value = False Estim.Value = False Me.Hide End Sub Private Sub Cancelar_Click() SORTIR = True Unload Me End Sub Private Sub Multiple_Click() If Multiple Then Tipus.Width = 205 Otros.Enabled = False End If End Sub Private Sub Simple_Click() If Simple Then Rest.Selected(k - 2) = True Otros.Enabled = True Tipus.Width = 100 End If

Page 17: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

16

End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub

Page 18: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

17

Attribute VB_Name = "C" Option Explicit Declare Function GetSystemMetrics Lib "user32" (ByV al nIndex As Long) As Long Public B() As Double, CTL As Control, CONVERG As Do uble, ERROR_COMBINACIO As Boolean, ERR_LEC As Boole an, _ F As Integer, FULL As String, FULL_R As Stri ng, GL() As Integer, G2SWEEP() As Double, IC As Int eger, _ IND() As Long, INOU As Integer, ITER As Inte ger, IX As Integer, IY As Integer, k As Integer, _ LINK As Integer, LVAR() As String, MCOV() As Double, N As Long, NPES As Integer, NTPES As Doubl e, _ NTPESM As Double, NX As Integer, NY As Integ er, OBRIR As Integer, OPT(), PES() As Double, PREDI CS(), R(), _ RESTRICS(), R_XY As Range, SIG As Double, SO RTIR As Boolean, SUMS() As Double, tests(), _ TIPUS_ANALISI As Integer, TITOL As String, V X() As Integer, XY() As Double, XYp(), Y() As Doubl e Sub CC_() Dim i1 As Integer, i2 As Integer, no_mes_fulls As B oolean, vzoom ''''''''''''''''''''''''''''''''''''''''''' 'Verifica la correcta estructura de treball ''''''''''''''''''''''''''''''''''''''''''' If Not C_CONTEXTVALID(TITOL) Then Exit Sub ''''''''''''''''''''''''''''''''''''''''' 'Carrega el quadre de diàleg dels crèdits ''''''''''''''''''''''''''''''''''''''''' If OBRIR = 1 Then C0_Credits.Show '''''''''''''''''''''''''''''''''''''''''''''''' 'Carrega el quadre de diàleg de captura de dades '''''''''''''''''''''''''''''''''''''''''''''''' REITERAR: INOU = 0 If Not Application.ScreenUpdating Then Application. ScreenUpdating = True Dim v() As String i2 = -1 For i1 = 1 To Worksheets.Count If InStr(1, ActiveWorkbook.Sheets(i1).Name, "_R ESULTS", 1) = 0 Then i2 = i2 + 1 ReDim Preserve v(i2) v(i2) = ActiveWorkbook.Sheets(i1).Name End If Next i1 ERR_LEC = True SORTIR = False If INOU > 0 Then C1_Captura.Cancelar.Caption = "Ter minar" Do While ERR_LEC = True With C1_Captura With .ListBox_fulls .Move Height:=Application.min(88, 11 * Works heets.Count), Left:=5, Top:=5, Width:=210 .List = v End With .Show End With If SORTIR Then ERR_LEC = False Loop If SORTIR Then GoTo FORA no_mes_fulls = False Call C_FULL(no_mes_fulls) 'Crea i configura el fu ll de càlcul on escriu els RESULTATS If no_mes_fulls Then Exit Sub Application.ScreenUpdating = False Application.DisplayAlerts = False ActiveWindow.DisplayWorkbookTabs = False Sheets.Add(After:=Sheets(FULL), Count:=1).Name = FU LL_R F = 3 Sheets(FULL).Activate If TIPUS_ANALISI = 1 Then Call M1_(1) If TIPUS_ANALISI = 2 Then Call M2_(1) If TIPUS_ANALISI = 3 Then Call M3_(1) If TIPUS_ANALISI = 4 Then Call M4_(1) If TIPUS_ANALISI = 5 Then Call M5_(1) If TIPUS_ANALISI = 6 Then Call M6_(1) If TIPUS_ANALISI = 7 Then Call M7_(1)

Page 19: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

18

If SORTIR And INOU = 0 Then Sheets(FULL_R).Delete Sheets(FULL).Activate GoTo REITERAR End If '''''''''''''''''''''''''''''''''''''''''''''''' 'Finalitza la configuració del full de resultats '''''''''''''''''''''''''''''''''''''''''''''''' vzoom = GetSystemMetrics(0) / 7.6 Sheets(FULL_R).Activate With ActiveSheet.PageSetup .BlackAndWhite = True .BottomMargin = Application.InchesToPoints(0.3937 00787401575) .FooterMargin = Application.InchesToPoints(0.1968 50393700787) .HeaderMargin = Application.InchesToPoints(0.1968 50393700787) .LeftFooter = "&""Arial,Negrita""&8" & "Fecha: " & "&D" & " Hora: " & "&T" .LeftMargin = Application.InchesToPoints(0.393700 787401575) .RightFooter = "&""Arial,Negrita""&8" & "Página: " & "&P" & " de " & "&N" .RightHeader = "&""Arial,Negrita""&8" & TITOL & " " & Chr(169) & " " & Chr(174) .RightMargin = Application.InchesToPoints(0.39370 0787401575) .TopMargin = Application.InchesToPoints(0.3937007 87401575) .ZOOM = 95 End With ActiveWindow.View = xlPageBreakPreview ActiveSheet.VPageBreaks(1).DragOff Direction:=xlToR ight, RegionIndex:=1 ActiveWindow.View = xlNormalView With ActiveWindow .DisplayWorkbookTabs = True .ZOOM = IIf(vzoom - Int(vzoom) < 0.5, Int(vzoom) + 1, Int(vzoom) + 2) End With MsgBox "Consulte la nueva hoja " & FULL_R, vbInform ation, TITOL Sheets(FULL).Activate GoTo REITERAR FORA: ActiveWindow.DisplayWorkbookTabs = True Application.ScreenUpdating = True Application.DisplayAlerts = True OBRIR = 0 End Sub Function C_CONTEXTVALID(TITOL) As Boolean Dim win As Window, i1 As Integer TITOL = "MicroEconometría" C_CONTEXTVALID = True If Val(Application.Version) < 9 Then C_CONTEXTVALID = False MsgBox "Este complemento sólo funciona con EXCEL -2000 o posterior.", vbCritical, TITOL Exit Function End If i1 = 0 For Each win In Application.Windows If win.Visible Then i1 = i1 + 1 Next If i1 = 0 Then C_CONTEXTVALID = False MsgBox "Debe haber al menos un libro activo, par a poder trabajar con este complemento.", vbCritical , TITOL Exit Function End If If ActiveWorkbook.ProtectStructure = True Then C_CONTEXTVALID = False MsgBox "El libro " & ActiveWorkbook.Name & " tie ne la estructura protegida, " & _ "debe desprotegerlo para poder trabajar c on este complemento.", vbCritical, TITOL Exit Function End If End Function Sub C_FULL(no_mes_fulls) Dim no_results As Boolean, i1 As Integer, i2 As Int eger FULL_R = "" no_results = True For i1 = 1 To ActiveWorkbook.Worksheets.Count If Right(ActiveWorkbook.Sheets(i1).Name, 9) = " _RESULTS9" Then MsgBox "Tiene 10 resultados asociados a la H oja de cálculo " & FULL & ", debe borrar el último, " & _ ActiveWorkbook.Sheets(i1).Name & ", p ara poder continuar.", vbCritical, TITOL

Page 20: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

19

no_mes_fulls = True Exit Sub Else For i2 = 8 To 0 Step -1 If ActiveWorkbook.Sheets(i1).Name = FULL & "_RESULTS" & IIf(i2 <> 0, i2, "") Then FULL_R = FULL & "_RESULTS" & i2 + 1 no_results = False GoTo salta End If Next i2 End If Next i1 salta: If no_results Then FULL_R = FULL & "_RESULTS" End Sub Sub C_G2SWEEP(opcio As Integer, c, m, obs, ncols, v tol As Double, ERROR_COMBINACIO) ''''''''''''''''''' 'ALGORITME G2SWEEP' ''''''''''''''''''' Dim d1 As Double, d2 As Double, i1 As Integer, i2 A s Integer, i3 As Integer, j1 As Integer ReDim aux(1 To ncols) As Double, tol(1 To ncols - 1 ) As Double '''''''''''''''''''''''' 'Defineix la tolerància' '''''''''''''''''''''''' For i1 = 1 To ncols - 1 tol(i1) = (m(i1, i1) - IIf(c = 1, ((m(1, i1) ^ 2) / obs), 0)) * vtol If tol(i1) = 0 Then tol(i1) = vtol Next i1 For i1 = 1 To ncols - 1 For i2 = i1 To i1 If m(i2, i2) < tol(i2) Then If opcio <> 0 Then For i3 = 1 To ncols m(i2, i3) = 0 m(i3, i2) = 0 Next i3 Else ERROR_COMBINACIO = True Exit Sub End If Else d1 = m(i2, i2) For j1 = 1 To ncols m(i2, j1) = m(i2, j1) / d1 aux(j1) = m(i2, j1) Next j1 End If Next i2 For i2 = 1 To ncols If i2 <> i1 Then d2 = m(i2, i1) For j1 = 1 To ncols m(i2, j1) = m(i2, j1) - (d2 * aux(j1 )) Next j1 m(i2, i1) = -d2 / d1 End If Next i2 m(i1, i1) = 1 / d1 Next i1 End Sub Sub C_RESTRICCIONES_1(opcio As Integer, m, a, br, e r_es, Estim, fr, gln, irest, n_r) '''''''''''''''''''''''''' 'opcio=0 REGRESION 'opcio=1 LOGIT y PROBIT 'opcio=2 LOGIT MULTINOMIAL 'opcio=3 LOGIT CONDICIONAL 'opcio=4 LOGIT MIXTO 'opcio=5 COUNT DATA '''''''''''''''''''''''''' Dim avis As Boolean, beta As String * 1, i1 As Inte ger, i2 As Integer, _ j1 As Integer, k1 As Integer, l1 As Integer, pr imer As Boolean, q As Integer, _ qm() As Double, r1() As Double, r2() As Double, signe As String, sr() As String, _ tit As String, xheight As Integer, xwidth As In teger ReDim RESTRICS(1 To k + 3, 1 To 2)

Page 21: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

20

''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''' 'Significat de RESTRICS() ' ' ' 'RESTRICS(i1, 1) = R ' 'RESTRICS(K + 1, 1) = R ' 'RESTRICS(i1, 2) = R (en format de cadena) ' 'RESTRICS(K + 2, 1) = Nombre de retriccions quan co ntrast múltiple, si es simple es 1 ' 'RESTRICS(K + 2, 2) = Tipus de restricció (simple=0 , múltiple=1) ' 'RESTRICS(K + 3, 1) = Nou contrast (True o False) ' 'RESTRICS(K + 3, 2) = Nova estimació (True o False) ' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''' If opcio = 0 Then tit = "Modelos de regresión: Rest ricciones lineales." If opcio = 1 Then tit = "Modelos Logit y Probit: Re stricciones lineales." If opcio = 2 Then tit = "Modelo Logit multinomial: Restricciones lineales." If opcio = 3 Then tit = "Modelo Logit condicional: Restricciones lineales." If opcio = 4 Then tit = "Modelo Logit mixto: Restri cciones lineales." If opcio = 5 Then tit = "Modelo 'Count data': Restr icciones lineales." Call C_RESTRICCIONES_2(opcio) irest = 0 primer = True SORTIR = False RESTRICS(k + 2, 2) = 0 REITERAR: ERR_LEC = True If RESTRICS(k + 2, 2) = 0 Then RESTRICS(k + 2, 1) = 1 q = 1 irest = irest + 1 Else If primer Then q = 0 irest = irest + 1 End If q = q + 1 End If Do While ERR_LEC With C3_Restricciones .Caption = tit & IIf(irest > 1, " (Test núm. " & irest & ")", "") .Estim.Visible = IIf(opcio <> 0, False, True) For Each CTL In C3_Restricciones.Controls If Left(CTL.Name, 2) = "Tb" Then CTL.Value = "0" Next CTL If RESTRICS(k + 2, 2) = 0 Then If opcio = 0 Then .Estim.Visible = True .Label1.Visible = False .Otros.Visible = IIf(irest = 5, False, True ) .Simple.Value = True .Tipus.Visible = True Else If q <> 1 Then With .Label1 .Caption = "Restricción múltiple núm. " & q & " de " & RESTRICS(k + 2, 1) .Left = 5 .Visible = True End With .Tipus.Visible = False End If If opcio = 0 Then .Estim.Visible = False End If .Otros.Enabled = IIf(q = RESTRICS(k + 2, 1) An d irest < 5, True, False) .Show If SORTIR Then ERR_LEC = False End With Loop If SORTIR Then GoTo FORA ReDim Preserve Estim(1 To irest), fr(1 To irest), g ln(1 To irest), n_r(1 To irest), r1(1 To k, 1 To q) , r2(1 To q), _ sr(1 To k, 1 To q) If opcio = 0 Then Estim(irest) = RESTRICS(k + 3, 2) Else Estim(irest) = False For j1 = 1 To k r1(j1, q) = RESTRICS(j1, 1) sr(j1, q) = RESTRICS(j1, 2) Next j1 r2(q) = RESTRICS(k + 1, 1)

Page 22: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

21

''''''''''''''''''''''''''''''''''' 'Identificador de les restriccions' ''''''''''''''''''''''''''''''''''' If RESTRICS(k + 2, 2) = 0 Then n_r(irest) = "" Else n_r(irest) = IIf(q = 1, "", n_r(irest) & ";") If opcio < 2 Then k1 = 0 Else k1 = KI * (JJJ - 1) ' k1 = a(2) * (a(1) - 1) For i1 = 1 To k If opcio < 2 Or opcio = 5 Then i2 = k1 beta = "b" Else i2 = IIf(KE = 0, 0, IIf(i1 <= k1, 0, k1)) If opcio = 2 Then beta = "b" If opcio = 3 Then beta = "g" If opcio = 4 Then beta = IIf(KE = 0, "b", II f(i1 <= k1, "b", "g")) End If If sr(i1, q) <> "0" Then signe = IIf(Left(sr(i1, q), 1) = "-", "-", " +") If Left(sr(i1, q), 1) = "-" Then sr(i1, q) = Mid(sr(i1, q), 2, Len(sr(i1, q))) Else If n_r(irest) = "" Or Right(n_r(irest), 1 ) = ";" Then signe = "" End If n_r(irest) = n_r(irest) & signe & IIf(sr(i1, q) = "1", "", "(" & sr(i1, q) & ")") & beta & i1 - i2 End If Next i1 n_r(irest) = n_r(irest) & "=" & r2(q) If RESTRICS(k + 2, 2) = 1 And q < RESTRICS(k + 2, 1 ) Then primer = False GoTo REITERAR End If ''''''''''''''''''''''''''''''''''''' 'Càlcul del contrast de restriccions' ''''''''''''''''''''''''''''''''''''' ReDim qm(1 To RESTRICS(k + 2, 1) + 1, 1 To RESTRICS (k + 2, 1) + 1), rbr(1 To RESTRICS(k + 2, 1)) As Do uble For i1 = 1 To RESTRICS(k + 2, 1) For j1 = 1 To RESTRICS(k + 2, 1) For k1 = 1 To k For l1 = 1 To k qm(i1, j1) = qm(i1, j1) + (r1(k1, j 1) * m(k1, l1) * r1(l1, i1)) Next l1 Next k1 Next j1 Next i1 Call C_G2SWEEP(1, 1, qm, N, RESTRICS(k + 2, 1) + 1, 0.00000001, False) For i1 = 1 To RESTRICS(k + 2, 1) For j1 = 1 To k rbr(i1) = rbr(i1) + (r1(j1, i1) * B(j1)) Next j1 rbr(i1) = r2(i1) - rbr(i1) Next i1 For i1 = 1 To RESTRICS(k + 2, 1) For j1 = 1 To RESTRICS(k + 2, 1) fr(irest) = fr(irest) + (rbr(i1) * qm(i1, j 1) * rbr(j1)) Next j1 Next i1 gln(irest) = q If opcio = 0 Then '''''''''''''''''''''''''''''''''' 'Càlcul de l'estimador restringit' '''''''''''''''''''''''''''''''''' If Estim(irest) Then ReDim Preserve a(1 To 5, 1 To irest), br(1 To k, 1 To irest), er_es(1 To k, 1 To irest) Call C_RESTRICCIONES_3(a, br, er_es, fr, ires t, q, qm, rbr, r1) End If fr(irest) = fr(irest) / q End If If RESTRICS(k + 3, 1) And irest < 5 Then If RESTRICS(k + 2, 2) = 0 Then GoTo REITERAR Else RESTRICS(k + 2, 2) = 0 primer = True GoTo REITERAR End If

Page 23: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

22

End If FORA: Unload C3_Restricciones End Sub Sub C_RESTRICCIONES_2(opcio) ''''''''''''''''''''''''''''''''''' 'Desplegament del quadre de diàleg' ''''''''''''''''''''''''''''''''''' Dim Line As Integer Dim i1 As Integer, i2 As Integer, k1 As Integer, xh eight As Integer, xwidth As Integer ReDim Frames(1 To k) As MSForms.Frame, Labs(1 To k) As MSForms.Label, Texts(1 To k) As MSForms.TextBox , _ v(k - 2) As Integer For i1 = 0 To k - 2 v(i1) = k - i1 Next i1 k1 = IIf(k <= 10, k, IIf(k <= 20, k - 10, k - 20)) xheight = IIf(k <= 10, 145, IIf(k <= 20, 195, 245)) xwidth = Application.max(IIf(k >= 10, 745, 330), (( k1 - 1) * 68) + 133) With C3_Restricciones .Height = xheight .Width = xwidth With .Aceptar .Left = (xwidth / 2) - 45 .Top = xheight - 50 End With With .Cancelar .Left = xwidth / 2 .Top = xheight - 50 End With With .Estim .Left = xwidth - 105 .Top = xheight - 50 .Visible = IIf(opcio <> 0, False, True) End With With .Fr_r .Left = (IIf(k <= 10, k - 1, 9) * 68) + 73 + II f(k = 2, 60, IIf(k = 3, 30, 0)) .Tb_r.Value = "0" .Top = IIf(k <= 10, 45, IIf(k <= 20, 95, 145)) End With .Otros.Top = xheight - 50 With .Rest .List = v .Selected(k - 2) = True End With For i1 = 1 To k i2 = IIf(i1 <= 10, i1, IIf(i1 <= 20, i1 - 10, i1 - 20)) Set Frames(i1) = .Controls.Add("forms.Frame.1 ") 'Frame (per a cada variable) With Frames(i1) .Height = 45 .Left = 68 * (i2 - 1) + 5 + IIf(k = 2, 60, 0) + IIf(k = 3, 30, 0) .Name = "Fr" & i1 .Top = IIf(i1 <= 10, 45, IIf(i1 <= 20, 95, 145)) .Width = 65 Set Labs(i1) = .Controls.Add("forms.Label.1 ") 'Label (dins del Frame de cada variable) With Labs(i1) .AutoSize = False .BorderStyle = 0 If opcio <= 1 Then .Caption = Chr(223) & i1 & Chr(10) & L VAR(i1, 2) ElseIf opcio = 2 Or opcio = 3 Then .Caption = IIf(opcio = 2, Chr(223), "y ") & i1 & Chr(10) & LV(i1) ElseIf opcio = 4 Then .Caption = IIf(i1 <= KI * (JJJ - 1), C hr(223), "y") & i1 & Chr(10) & LV(i1) End If .Font.Size = 8 .Height = 18 .Left = 0 .Name = "Lb" & i1 .TextAlign = 2 .Top = 0 .Width = 62 .WordWrap = False End With Set Texts(i1) = .Controls.Add("forms.TextBo x.1") 'TextBox (dins del Frame de cada variable) With Texts(i1)

Page 24: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

23

.Font.Size = 8 .Height = 15 .Left = 5 .MaxLength = 9 .Name = "Tb" & i1 .TextAlign = 3 .Top = 25 .Value = "0" .Width = 50 .WordWrap = False End With End With Next i1 End With End Sub Sub C_RESTRICCIONES_3(a, br, er_es, fr, irest, q, q m, rbr, r1) '''''''''''''''''''''''''''''''''''''''''''''''' 'ESTIMADOR RESTRINGIT (només per a la regressió) '''''''''''''''''''''''''''''''''''''''''''''''' Dim aux1() As Double, aux2() As Double, i1 As Integ er, j1 As Integer, k1 As Integer, l1 As Integer ReDim aux1(1 To k, 1 To k), aux2(1 To k, 1 To k) a(2, irest) = IIf(fr(irest) + Sq(2) < Sq(3), fr(ire st) + Sq(2), Sq(3)) a(1, irest) = Sq(3) - a(2, irest) a(3, irest) = Sqr(a(2, irest) / (N - (k - q))) a(4, irest) = 1 - (a(2, irest) / Sq(3)) a(5, irest) = IIf(a(4, irest) = 0, 0, 1 - ((a(2, ir est) / (N - (k - q))) / (Sq(3) / (N - 1)))) For i1 = 1 To k For j1 = 1 To k For k1 = 1 To RESTRICS(k + 2, 1) For l1 = 1 To RESTRICS(k + 2, 1) aux1(i1, j1) = aux1(i1, j1) + (r1(i 1, l1) * qm(k1, l1) * r1(j1, k1)) Next l1 Next k1 Next j1 Next i1 For i1 = 1 To k For j1 = 1 To k For k1 = 1 To k For l1 = 1 To k aux2(i1, j1) = aux2(i1, j1) + (IXPX (k1, j1) * aux1(k1, l1) * IXPX(l1, i1)) Next l1 Next k1 Next j1 Next i1 For i1 = 1 To k If IXPX(i1, i1) - aux2(i1, i1) > 0 Then er_es(i1, irest) = Sqr((a(3, irest) ^ 2) * ( IXPX(i1, i1) - aux2(i1, i1))) If (IXPX(i1, i1) / aux2(i1, i1)) - 1 <= 0.00 000001 Then er_es(i1, irest) = 0 Else er_es(i1, irest) = 0 End If Next i1 ReDim aux1(1 To k), aux2(1 To k) For i1 = 1 To k For j1 = 1 To RESTRICS(k + 2, 1) For k1 = 1 To RESTRICS(k + 2, 1) aux1(i1) = aux1(i1) + (r1(i1, k1) * qm( j1, k1) * rbr(j1)) Next k1 Next j1 Next i1 For i1 = 1 To k For j1 = 1 To k aux2(i1) = aux2(i1) + (IXPX(i1, j1) * aux1( j1)) Next j1 Next i1 For i1 = 1 To k br(i1, irest) = B(i1) + aux2(i1) Next i1 End Sub Sub C_CREAR(opcio As Integer) Dim AjudaMenu As CommandBarControl, ECOMenu As Comm andBarPopup On Error Resume Next Set ECOMenu = CommandBars(1).Controls("MicroEconome tría " & Chr(169) & " " & Chr(174)) If ECOMenu Is Nothing Then Set AjudaMenu = CommandBars(1).FindControl(ID:=3 0010) If AjudaMenu Is Nothing Then

Page 25: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

24

Set ECOMenu = CommandBars(1).Controls.Add(Typ e:=msoControlPopup, Temporary:=True) Else Set ECOMenu = CommandBars(1).Controls.Add(Typ e:=msoControlPopup, Temporary:=True, Before:=AjudaMenu.Index) End If With ECOMenu .BeginGroup = True .Caption = "&MicroEconometría " & Chr(169) & " " & Chr(174) .OnAction = "CC_" End With End If End Sub Sub C_ESBORRAR(opcio As Integer) Dim ECOMenu As CommandBarPopup, ECOItem As CommandB arButton On Error Resume Next Set ECOMenu = CommandBars(1).Controls("MicroEconome tría " & Chr(169) & " " & Chr(174)) If ECOMenu Is Nothing Then Exit Sub Else ECOMenu.De lete End Sub Sub C_ORDENA(opcio, inici, final) ' C_ORDENA(1, i2, i2) --> GQ (regressió) ' C_ORDENA(2, 1, k) --> Bootstrap ' C_ORDENA(3, 1, 1) --> Residus (regressió) ' C_ORDENA(4, K + 1, K + 1) --> Tobit i Heckman ' C_ORDENA(5, 1, NI + IIf(II(5, 1) Or II( 6, 1), NI, 0) + 1) --> Indices Dim it As Integer, i1 As Long If opcio = 1 Or opcio = 4 Then 'ordenació: GQ, Tobit-Heckman ReDim IND(1 To N, 1 To 1), Y(1 To N) For i1 = 1 To N Y(i1) = XY(i1, inici) + ((i1 / N) ^ 0.001) IND(i1, 1) = i1 Next i1 Call C_ORDENA_1(1, N, 1) ElseIf opcio = 2 Then 'ordenació: "bootstrap" ReDim IND(1 To 1000, inici To final), Y(1 To 100 0) For it = inici To final For i1 = 1 To 1000 Y(i1) = XY(i1, it) + ((i1 / N) ^ 0.001) IND(i1, it) = i1 Next i1 Call C_ORDENA_1(1, 1000, it) Next it ElseIf opcio = 3 Then 'ordenació: Residus ReDim IND(1 To N, 1 To 1), Y(1 To N) For i1 = 1 To N Y(i1) = RG.Columns(2).Rows(i1) + ((i1 / N) ^ 0.001) IND(i1, 1) = i1 Next i1 Call C_ORDENA_1(1, N, 1) ElseIf opcio = 5 Then 'ordenació: Indices ReDim IND(1 To N, 1 To final), Y(1 To N) For it = 1 To final For i1 = 1 To N Y(i1) = XY(i1, it) + ((i1 / N) ^ 0.001) IND(i1, it) = i1 Next i1 Call C_ORDENA_1(1, N, it) Next it End If End Sub Sub C_ORDENA_1(lim_i As Long, lim_s As Long, column a As Integer) Dim i As Long, j As Long, aux As Double, y1 As Doub le, ind1 As Long i = lim_i j = lim_s aux = Y((lim_i + lim_s) / 2) While i <= j While (Y(i) < aux) And (i < lim_s) i = i + 1 Wend While (aux < Y(j)) And (j > lim_i) j = j - 1

Page 26: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

25

Wend If i <= j Then y1 = Y(i) Y(i) = Y(j) Y(j) = y1 ind1 = IND(i, columna) IND(i, columna) = IND(j, columna) IND(j, columna) = ind1 i = i + 1 j = j - 1 End If Wend If lim_i < j Then C_ORDENA_1 lim_i, j, columna If i < lim_s Then C_ORDENA_1 i, lim_s, columna End Sub

Page 27: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

26

Attribute VB_Name = "M1_Regresion" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVISEXOGENES As Boolean Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Long, nobs ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then NY = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable endógena.", vbCritical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VX(1 To i2) VX(i2) = i1 NX = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar al menos una variable e xógena.", vbCritical, TITOL Exit Sub End If For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 For i1 = 1 To NX If NY = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y exógena.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If NY = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y factor de elevación.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If NPES = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(VX(i1), 1) & " no puede ser e xógena y factor de elevación.", vbCritical, TITOL Exit Sub End If Next i1 End If IY = 0 For i1 = 1 To R_XY.Columns.Count If obs.Selected(i1 - 1) Then IY = i1 Exit For End If Next i1 If IY <> 0 Then If IY = NY Then ERR_LEC = True Me.Hide MsgBox LVAR(IY, 1) & " no puede ser identific ador de observación y endógena.", vbCritical, TITOL Exit Sub

Page 28: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

27

End If For i1 = 1 To NX If IY = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(IY, 1) & " no puede ser ident ificador de observación y exógena.", vbCritical, TI TOL Exit Sub End If Next i1 If NPES <> 0 Then If IY = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(IY, 1) & " no puede ser identi ficador de observación y factor de elevación.", vbC ritical, TITOL Exit Sub End If End If End If If Application.Count(R_XY.Columns(NY)) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(NY, 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If Application.Count(R_XY.Columns(VX(i1))) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(V X(i1), 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If Application.Count(R_XY.Columns(NPES)) <> N Or Application.CountIf(R_XY.Columns(NPES), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N PES, 1) & " es negativo, nulo o no numérico.", vbCr itical, TITOL Exit Sub End If End If If Constante.Value = True Then IC = 1 Else IC = 0 k = IC + NX ReDim G2SWEEP(1 To k + 1, 1 To k + 1), XY(1 To N, 1 To k + 1), PES(1 To N) If NPES <> 0 Then NTPESM = Application.Average(R_XY.Rows.Columns(N PES)) NTPES = Application.Sum(R_XY.Rows.Columns(NPES)) / NTPESM Else NTPESM = 1 NTPES = N End If For i3 = 1 To N If NPES <> 0 Then PES(i3) = R_XY.Rows(i3).Colum ns(NPES) / NTPESM Else PES(i3) = 1 If IC = 1 Then XY(i3, 1) = 1 For i1 = 1 To NX XY(i3, IC + i1) = R_XY.Rows(i3).Columns(VX( i1)) Next i1 XY(i3, k + 1) = R_XY.Rows(i3).Columns(NY) For i1 = 1 To k + 1 For i2 = i1 To k + 1 G2SWEEP(i1, i2) = G2SWEEP(i1, i2) + (XY (i3, i1) * XY(i3, i2) * PES(i3)) Next i2 Next i1 Next i3 For i1 = 1 To k + 1 For i2 = i1 + 1 To k + 1 G2SWEEP(i2, i1) = G2SWEEP(i1, i2) Next i2 Next i1 ReDim XPX(1 To k + 1, 1 To k + 1) For i1 = 1 To k + 1 For i2 = 1 To k + 1 XPX(i1, i2) = G2SWEEP(i1, i2) Next i2 Next i1 ERROR_COMBINACIO = False

Page 29: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

28

Call C_G2SWEEP(0, IC, G2SWEEP, N, k + 1, 0.00000001 , ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide MsgBox "El modelo no es de rango completo.", vbC ritical, TITOL Exit Sub End If If IC = 1 Then LVAR(1, 2) = "Const." For i1 = 1 To NX LVAR(IC + i1, 2) = LVAR(VX(i1), 1) Next i1 LVAR(k + 1, 2) = LVAR(NY, 1) Call ANALISIS(1) End Sub Private Sub Cancelar_Click() SORTIR = True NPES = 0 Unload Me End Sub Private Sub ANALISIS(opcio As Integer) Dim i1 As Integer, i2 As Integer, i3 As Long '''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul '''''''''''''''''''''''''''''''' ReDim OPT(23, 5) OPT(2, 0) = True OPT(3, 0) = True For i1 = 1 To 12 For Each CTL In Frame3.Controls If CTL.Name = "ch" & i1 Then OPT(i1, 0) = C TL.Value Next CTL Next i1 If k - IC = 1 Then OPT(6, 0) = False For i1 = 1 To 3 For Each CTL In Frame4.Controls If CTL.Name = "ch2" & i1 Then OPT(i1 + 20, 0) = CTL.Value Next CTL Next i1 If cros.Value Then T_DADES = "CS" Else T_DADES = "S T" SIG = n_sig.Value If OPT(11, 0) Then If R_XY.Columns.Count <= NX + IY + NPES + 1 Then Me.Hide MsgBox "No hay suficientes instrumentos para la opción de Estimación por Variables Instrumentale s.", vbCritical, TITOL ch11.Enabled = False OPT(11, 0) = False End If End If ''''''''''''''''''''''''''''''''''''''''''' 'Carrega els identificadors d'observacions' ''''''''''''''''''''''''''''''''''''''''''' ReDim LOBS(1 To N) LLARG = 0 If OPT(21, 0) Or OPT(22, 0) Or OPT(23, 0) Then If IY <> 0 Then LVAR(0, 2) = LVAR(IY, 1) Else LV AR(0, 2) = "Observación" i2 = 0 For i3 = 1 To N If IY <> 0 Then LOBS(i3) = R_XY.Rows(i3).Col umns(IY) Else LOBS(i3) = i3 If Len(LOBS(i3)) > i2 Then i2 = Len(LOBS(i3)) LLARG = i3 End If Next i3 End If Me.Hide End Sub Private Sub EXOGENES(opcio As Integer) Dim i1 As Integer

Page 30: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

29

AVISEXOGENES = False For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then AVISEXOGENES = True Exit For End If Next i1 If AVISEXOGENES Then For Each CTL In Me.Controls CTL.Enabled = True Next CTL If NPES <> 0 Then time.Enabled = False If k = 1 Or k > 30 Then ch5.Enabled = False If Not time Then cros.Value = True If N > 500 Or NPES <> 0 Then Frame4.Enabled = False For Each CTL In Frame4.Controls CTL.Enabled = False Next CTL End If If cros Then ch10.Enabled = False If NPES <> 0 Then ch9.Enabled = False ch10.Enabled = False End If Else NPES = 0 For Each CTL In Me.Controls If CTL.Name <> "Label1" And CTL.Name <> "Lab el2" And _ CTL.Name <> "ys" And CTL.Name <> "xs" And CTL.Name <> "Cancelar" Then CTL.Enabled = False Next CTL For i1 = 1 To R_XY.Columns.Count obs.Selected(i1 - 1) = False ps.Selected(i1 - 1) = False Next i1 cros.Value = False End If End Sub Private Sub cros_Click() If cros Then With ch10 .Enabled = False .Value = False End With End If End Sub Private Sub time_Click() If time And NPES = 0 Then ch10.Enabled = True End Sub Private Sub ps_Click() Dim i1 As Integer For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 If NPES <> 0 Then time.Enabled = False time.Value = False ch9.Enabled = False ch10.Enabled = False Frame4.Enabled = False For Each CTL In Frame4.Controls CTL.Enabled = False CTL.Value = False Next CTL End If End Sub Private Sub UserForm_Layout()

Page 31: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

30

n_sig.Move Height:=12, Left:=38, Top:=7, Width:=40 End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() Label2.Enabled = True xs.Enabled = True End Sub Private Sub xs_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call EXOGENES(1) End Sub

Page 32: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

31

Attribute VB_Name = "M1" Option Explicit Public AUTO(1 To 5), BOOTSTRAP() As Boolean, E() As Double, HAT() As Double, HETEROS(), IXPX() As Doub le, _ LLARG As Integer, LOBS() As String, P_BP As Boolean, P_CHOW() As Integer, RG As Range, Sq() As Double, _ S2 As Double, T_DADES As String * 2, VARS() As Integer, VI_X(), VI_Z(), XPX() As Double, YHAT() As Double Sub M1_(opcio As Integer) ''''''''''' 'REGRESSIÓ' ''''''''''' ''''''''''''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' ''''''''''''''''''''''''''''''''''''''''''''' 'opt(1,0) descriptiu (M1_01)' 'opt(2,0) anàlisi variança (M1_02)' 'opt(3,0) estimació m.q.o (M1_03)' 'opt(4,0) Prediccions "ex-post" (M1_04)' 'opt(5,0) restriccions (M1_05)' 'opt(6,0) multicol·linealitat (M1_06)' 'opt(7,0) Contrastos (M1_07)' 'opt(8,0) White (M1_08)' 'opt(9,0) Heteroscedasticitat (M1_09)' 'opt(10,0) Autocorrelació (M1_10)' 'opt(11,0) Variables instrumentals (M1_11)' 'opt(12,0) "Bootstrap" (M1_12)' 'opt(21,0) residus (M1_21)' 'opt(22,0) influència (M1_22)' 'opt(23,0) estabilitat (M1_23)' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria1: Mod elos de Regresión' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String, vsig(5) As Double For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 For i1 = 5 To 0 Step -1 If i1 > 0 Then vsig(5 - i1) = 0.05 * i1 Else vs ig(5 - i1) = 0.01 Next i1 TITOL = "MicroEconometría: Modelos de Regresión" h = Application.min(110, 11 * R_XY.Columns.Count) With M1_Regresion .ys.Move Height:=h, Left:=40, Top:=30, Width:=120 .ys.List = v .xs.Move Height:=h, Left:=165, Top:=30, Width:=12 0 .xs.List = v .ps.Move Height:=h, Left:=290, Top:=30, Width:=12 0 .ps.List = v .obs.Move Height:=h, Left:=415, Top:=30, Width:=1 20 .obs.List = v .n_sig.List = vsig .n_sig.Selected(4) = True End With ERR_LEC = True SORTIR = False NPES = 0 Do While ERR_LEC = True M1_Regresion.Show If SORTIR Then ERR_LEC = False Loop Unload M1_Regresion If SORTIR Then Exit Sub Call M1_00(1) If OPT(1, 0) Then Call M1_01(1) If OPT(2, 0) Then Call M1_02(1, 3.01) If OPT(3, 0) Then Call M1_03(1) If OPT(4, 0) Then Call M1_04(1) If OPT(5, 0) Then Call M1_05(1) If OPT(6, 0) Then Call M1_06(1) If OPT(7, 0) Then Call M1_07(1)

Page 33: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

32

If OPT(8, 0) Then Call M1_08(1) If OPT(9, 0) Then Call M1_09(1) If OPT(10, 0) Then Call M1_10(1) If OPT(11, 0) Then Call M1_11(1) If OPT(12, 0) Then Call M1_12(1) If OPT(21, 0) Then Call M1_21(LLARG) If OPT(22, 0) Then Call M1_22(LLARG) If OPT(23, 0) Then Call M1_23(1) INOU = INOU + 1 End Sub Private Sub M1_00(opcio As Integer) ''''''''''''''''''''' 'CALCULS PRELIMINARS' ''''''''''''''''''''' Dim i3 As Long, j1 As Integer, k1 As Integer ReDim B(1 To k), E(1 To N), GL(1 To 3), HAT(1 To N) , IXPX(1 To k, 1 To k), Sq(1 To 3), SUMS(1 To k + 1 , 1 To 3), _ YHAT(1 To N) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' 'Mitjanes(1), Sumes de quadrats(2) i Sumes de quadr ats corrregides(3) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' For j1 = 1 To k + 1 SUMS(j1, 1) = XPX(1, j1) / NTPES SUMS(j1, 2) = XPX(j1, j1) SUMS(j1, 3) = XPX(j1, j1) - IIf(IC = 1, ((SUMS( j1, 1) ^ 2) * NTPES), 0) Next j1 Sq(3) = IIf(IC = 1, SUMS(k + 1, 3), SUMS(k + 1, 2)) Sq(2) = G2SWEEP(k + 1, k + 1) Sq(1) = Sq(3) - Sq(2) GL(1) = k - IC GL(2) = N - k GL(3) = N - IC S2 = Sq(2) / GL(2) ''''''''''''''''''''''' 'Coeficients i inversa' ''''''''''''''''''''''' For k1 = 1 To k B(k1) = G2SWEEP(k1, k + 1) For j1 = 1 To k IXPX(k1, j1) = G2SWEEP(k1, j1) Next j1 Next k1 '''''''''''''''''''''''''''''''''''''''''''''' 'Residus, prediccions i diagonal "hat" matrix' '''''''''''''''''''''''''''''''''''''''''''''' For i3 = 1 To N YHAT(i3) = 0 For j1 = 1 To k YHAT(i3) = YHAT(i3) + (XY(i3, j1) * B(j1)) Next j1 E(i3) = XY(i3, k + 1) - YHAT(i3) If (OPT(21, 0) Or OPT(22, 0)) Then ReDim aux(1 To k) As Double HAT(i3) = 0 For j1 = 1 To k For k1 = 1 To k aux(j1) = aux(j1) + (XY(i3, k1) * I XPX(k1, j1)) Next k1 Next j1 For j1 = 1 To k HAT(i3) = HAT(i3) + (aux(j1) * XY(i3, j 1)) Next j1 HAT(i3) = HAT(i3) * PES(i3) End If Next i3 End Sub Private Sub M1_01(opcio As Integer) ''''''''''''''''''''''''' 'ESTADÍSTICA DESCRIPTIVA' '''''''''''''''''''''''''

Page 34: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

33

Dim aux(1 To 1), i1 As Integer, i2 As Integer, i3 A s Integer ReDim ss(1 To k + 1, 1 To 3) For i1 = 1 To k + 1 If IC = 1 Then For i2 = 1 To 3 ss(i1, i2) = SUMS(i1, i2) Next i2 Else If i1 = k + 1 Then i3 = NY Else i3 = VX(i1) If NPES = 0 Then ss(i1, 1) = Application.Ave rage(R_XY.Columns(i3)) Else ss(i1, 1) = Application.SumProduct(R_XY.Columns(i3), R_XY.Colum ns(NPES)) / NTPES ss(i1, 2) = SUMS(i1, 2) ss(i1, 3) = SUMS(i1, 2) - ((ss(i1, 1) ^ 2) * NTPES) End If Next i1 For i2 = 1 To 2 ReDim R(1 To k - IC + 3 + IIf(NPES <> 0, 1, 0), 1 To IIf(i2 = 1, 6, IIf(NPES = 0, 7, 5))) R(1, 1) = "Variable" R(1, 2) = IIf(i2 = 1, "N", "Desviación" & Chr(1 0) & "Estándar") R(1, 3) = IIf(i2 = 1, IIf(NPES = 0, "Valor" & C hr(10) & "mínimo", "N" & Chr(10) & "Ponderado"), "V arianza") R(1, 4) = IIf(i2 = 1, IIf(NPES = 0, "Media", "V alor" & Chr(10) & "mínimo"), "Suma" & Chr(10) & "Cu adrados") R(1, 5) = IIf(i2 = 1, IIf(NPES = 0, "Mediana", "Media"), "S. Cuadrados" & Chr(10) & "corr.") If i2 = 1 Then R(1, 6) = "Valor" & Chr(10) & "m áximo" If i2 = 2 And NPES = 0 Then R(1, 6) = "Asimetría" R(1, 7) = "Curtosis" End If For i1 = 1 To k - IC + 1 If i1 = k - IC + 1 Then i3 = NY Else i3 = V X(i1) R(i1 + 2, 1) = LVAR(i1 + IC, 2) R(i1 + 2, 2) = IIf(i2 = 1, N, Sqr(ss(i1 + I C, 3) / (N - 1))) R(i1 + 2, 3) = IIf(i2 = 1, IIf(NPES = 0, Ap plication.min(R_XY.Columns(i3)), NTPES), ss(i1 + IC , 3) / (N - 1)) R(i1 + 2, 4) = IIf(i2 = 1, IIf(NPES = 0, ss (i1 + IC, 1), Application.min(R_XY.Columns(i3))), s s(i1 + IC, 2)) R(i1 + 2, 5) = IIf(i2 = 1, IIf(NPES = 0, Ap plication.Median(R_XY.Columns(i3)), ss(i1 + IC, 1)) , ss(i1 + IC, 3)) If i2 = 1 Then R(i1 + 2, 6) = Application.m ax(R_XY.Columns(i3)) If i2 = 2 And NPES = 0 Then R(i1 + 2, 6) = Application.Skew(R_XY.Col umns(i3)) R(i1 + 2, 7) = Application.Kurt(R_XY.Col umns(i3)) End If Next i1 If NPES <> 0 Then R(k - IC + 4, 1) = "Variable de ponderación: " & LVAR(NPES, 1) If i2 = 1 And k > 27 Then aux(1) = 1 If i2 = 2 Then aux(1) = 1 Call M1_ESCRIPTURA(1, IIf(i2 = 1, "ESTADÍSTICA DESCRIPTIVA", ""), aux) Next i2 End Sub Private Sub M1_02(opcio As Integer, v As Double) ''''''''''''''''''''''''' 'ANÀLISI DE LA VARIÀNCIA' ''''''''''''''''''''''''' 'opcio=1 MQO ' 'opcio=2 MQ2E ' ''''''''''''''''''''''''' Dim aux(1 To 1), i1 As Integer ReDim R(1 To 6 + IIf(NPES <> 0, 1, 0), 1 To 6) R(1, 1) = "Variable dependiente: " & LVAR(k + 1, 2) R(1, 4) = "Número de observaciones: " & Format(N, " ###,0") R(2, 1) = "Variación" R(2, 2) = "SC" R(2, 3) = "gl" R(2, 4) = "SC/gl" R(2, 5) = "F" R(2, 6) = "Prob > F" R(3, 1) = "Explicada" R(4, 1) = "No Explicada" R(5, 1) = "Total" R(6, 1) = Chr(214) & "ECM = " If NPES <> 0 Then R(7, 1) = "Variable de ponderación: " & LVAR(NPE S, 1) R(7, 4) = "Observaciones ponderadas: " & Format( NTPES, "###,0") End If If opcio = 1 Then For i1 = 1 To 3 R(i1 + 2, 2) = Sq(i1)

Page 35: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

34

R(i1 + 2, 3) = GL(i1) If i1 < 3 Then R(i1 + 2, 4) = Sq(i1) / GL(i1 ) Next i1 R(3, 5) = (Sq(1) / GL(1)) / (Sq(2) / GL(2)) R(3, 6) = Application.FDist(R(3, 5), GL(1), GL(2 )) R(3, 6) = IIf(R(3, 6) < 0.0001, "< 0,0001", R(3, 6)) R(6, 2) = Sqr(S2) R(6, 3) = "R" & Chr(178) & " = " R(6, 4) = Sq(1) / Sq(3) R(6, 5) = "R" & Chr(178) & " corr = " R(6, 6) = 1 - ((Sq(2) / GL(2)) / (Sq(3) / GL(3)) ) Else R(3, 2) = Sq(3) - ((N - k) * v) R(4, 2) = ((N - k) * v) R(5, 2) = Sq(3) R(3, 3) = GL(1) R(4, 3) = GL(2) R(5, 3) = GL(3) R(3, 4) = (Sq(3) - ((N - k) * v)) / GL(1) R(4, 4) = (N - k) * v / GL(2) R(3, 5) = R(3, 4) / R(4, 4) R(3, 6) = Application.FDist(R(3, 5), GL(1), GL(2 )) R(3, 6) = IIf(R(3, 6) < 0.0001, "< 0,0001", R(3, 6)) R(6, 2) = Sqr(v) R(6, 3) = "R" & Chr(178) & " = " R(6, 4) = R(3, 2) / Sq(3) R(6, 5) = "R" & Chr(178) & " corr = " R(6, 6) = 1 - (((N - k) * v / GL(2)) / (Sq(3) / GL(3))) End If Call M1_ESCRIPTURA(2, "ANÁLISIS DE LA VARIANZA" & I If(opcio <> 1, " (MC2E)", ""), aux) End Sub Private Sub M1_03(opcio As Integer) ''''''''''''''' 'ESTIMACIÓ MQO' ''''''''''''''' Dim i1 As Integer, j1 As Integer, i3 As Long, num A s Double, den As Double ReDim aux(1 To 2, 1 To 1), R(1 To k + 2, 1 To 8), v arb(1 To k, 1 To k) As Double If k <= 18 Then OPT(3, 3) = True If k > 18 Then OPT(0, 0) = 3 With C2_Varis .Aceptar.Top = 60 .Cancelar.Top = 60 .Caption = "Modelos de Regresión: Estimación M C0" .c01.Caption = "Análisis de la varianza" .c01.Locked = True .c02.Caption = "Estimación de los parámetros" .c02.Locked = True .c03.Caption = "Matriz de varianzas y covarian zas" .c03.Value = False .c04.Visible = False .c05.Visible = False .Frame0.Height = 50 With .MultiPage1 .Height = 60 .Style = fmTabStyleNone .Value = 0 End With .Height = 105 .Show End With If SORTIR Then SORTIR = False Unload C2_Varis End If R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "Coeficiente" & Chr(10) & "Estandariz." R(1, 4) = "err. es." & Chr(10) & "Parámetro" R(1, 5) = "Valor t" R(1, 6) = "Prob |t|" R(1, 7) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" aux(1, 1) = Application.TInv(SIG, GL(2)) den = IIf(IC = 1, Sqr(SUMS(k + 1, 3) / (N - 1)), Sq r(SUMS(k + 1, 2) / (N - 1))) For i1 = 1 To k For j1 = 1 To k varb(i1, j1) = S2 * IXPX(i1, j1)

Page 36: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

35

Next j1 R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & " )" R(i1 + 2, 2) = B(i1) If i1 >= IC + 1 Then num = IIf(IC = 1, Sqr(SUMS(i1, 3) / (N - 1)) , Sqr(SUMS(i1, 2) / (N - 1))) R(i1 + 2, 3) = B(i1) * num / den End If R(i1 + 2, 4) = Sqr(varb(i1, i1)) R(i1 + 2, 5) = B(i1) / R(i1 + 2, 4) R(i1 + 2, 6) = Application.TDist(Abs(R(i1 + 2, 5)), GL(2), 2) R(i1 + 2, 6) = IIf(R(i1 + 2, 6) < 0.0001, "< 0, 0001", R(i1 + 2, 6)) R(i1 + 2, 7) = B(i1) - aux(1, 1) * R(i1 + 2, 4) R(i1 + 2, 8) = B(i1) + aux(1, 1) * R(i1 + 2, 4) Next i1 aux(1, 1) = IIf(k <= 18, 0, IIf(OPT(3, 3) = True, I If(k > 27, 1, 0), 1)) Call M1_ESCRIPTURA(3, "ESTIMACIÓN MCO", aux) If k > 1 And OPT(3, 3) Then Call M1_ESCRIPTURA_1(3, varb, B, "MATRIZ DE VARIANZAS y COVARIANZAS (MCO)" ) End Sub Private Sub M1_04(opcio As Integer) ''''''''''''''''''' 'PREDICCIÓ EX-POST' ''''''''''''''''''' With C2_Varis .Caption = "Modelos de Regresión: Predicción 'ex- post'" .Frame4.Height = 65 With .MultiPage1 .Height = 75 .Style = fmTabStyleNone .Value = 1 End With .Height = 95 End With Application.ScreenUpdating = True 'Això està bé aq uí ERR_LEC = True Do While ERR_LEC = True C2_Varis.Show If SORTIR Then ERR_LEC = False Loop Application.ScreenUpdating = False 'Això està bé aq uí Unload C2_Varis If SORTIR Then SORTIR = False Exit Sub End If Dim np As Integer, ip As Boolean np = UBound(XYp, 1) If UBound(XYp, 2) > k + 1 Then ip = True Dim den As Double, dim1 As Integer, i1 As Integer, i2 As Integer, j1 As Integer, _ llarg_p, k1 As Integer, maxim1 As Integer, rest a1 As Integer, tit As String ReDim aux(1 To 6), e_(1 To np) As Double, error_(1 To np) As Double, _ y_(1 To np) As Double, y_p(1 To np) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' ' 'Determina l'amplada de columna dels identificadors ' ''''''''''''''''''''''''''''''''''''''''''''''''''' ' aux(1) = 0 aux(2) = 0 llarg_p = 1 If ip Then For i1 = 1 To np aux(2) = XYp(i1, UBound(XYp, 2)) If Len(aux(2)) > aux(1) Then aux(1) = Len(aux(2)) llarg_p = i1 End If Next i1 With Cells(1, 11) aux(1) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7

Page 37: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

36

End With .Value = XYp(llarg_p, UBound(XYp, 2)) .Columns.AutoFit aux(2) = .ColumnWidth .Clear .ColumnWidth = aux(1) End With If aux(2) > 9.57 Then llarg_p = 2 End If aux(1) = llarg_p aux(2) = 0 aux(3) = aux(1) + aux(2) aux(4) = 0 aux(5) = Application.TInv(SIG, GL(2)) For i1 = 1 To np y_p(i1) = 0 For j1 = 1 To k y_p(i1) = y_p(i1) + (XYp(i1, j1) * B(j1)) Next j1 e_(i1) = XYp(i1, k + 1) - y_p(i1) aux(4) = aux(4) + Abs(e_(i1)) aux(6) = 0 For j1 = 1 To k For k1 = 1 To k aux(6) = aux(6) + (XYp(i1, j1) * IXPX(j 1, k1) * XYp(i1, k1)) Next k1 Next j1 error_(i1) = (aux(5) * Sqr(S2 * (1 + aux(6)))) y_(i1) = XYp(i1, k + 1) Next i1 If NPES <> 0 Then tit = " (Variable de Ponderación : " & LVAR(NPES, 1) & ")" Else tit = "" dim1 = IIf(np <= 70, np, 70) maxim1 = IIf(np <= 70, 1, Int(np / 70)) resta1 = IIf(np <= 70, 0, np - (maxim1 * 70)) If resta1 <> 0 Then maxim1 = maxim1 + 1 For i2 = 1 To maxim1 ReDim R(1 To IIf(i2 < maxim1, dim1 + 2, IIf(res ta1 = 0, dim1, resta1) + 9), 1 To 6 + aux(3)) R(1, 1) = "Observación" R(1, 1 + aux(3)) = "Valor" & Chr(10) & "observa do" R(1, 2 + aux(3)) = "Predicción" & Chr(10) & "pu ntual" R(1, 3 + aux(3)) = "Error de" & Chr(10) & "Pred icción" R(1, 4 + aux(3)) = "% Error s/" & Chr(10) & "ob servado" R(1, 5 + aux(3)) = "Intervalo Predicción" & Chr (10) & "(sig.=" & Format(SIG, "0.00") & ")" For i1 = 1 To IIf(i2 < maxim1, dim1, IIf(resta1 = 0, dim1, resta1)) j1 = i1 + ((i2 - 1) * 70) If ip Then R(i1 + 2, 1) = XYp(j1, UBound(XY p, 2)) Else R(i1 + 2, 1) = Str(j1) R(i1 + 2, 1 + aux(3)) = XYp(j1, k + 1) R(i1 + 2, 2 + aux(3)) = y_p(j1) R(i1 + 2, 3 + aux(3)) = e_(j1) If XYp(j1, k + 1) <> 0 Then R(i1 + 2, 4 + a ux(3)) = (e_(j1) / XYp(j1, k + 1)) R(i1 + 2, 5 + aux(3)) = y_p(j1) - error_(j1 ) R(i1 + 2, 6 + aux(3)) = y_p(j1) + error_(j1 ) Next i1 If i2 = maxim1 Then aux(5) = 0 k1 = IIf(aux(3) = 0, 3, 4) R(i1 + 2, k1) = "Valoración de la capacidad predictiva" R(i1 + 3, k1) = "Error Cuadrático Medio = " R(i1 + 3, k1 + 2) = Application.SumSq(e_) / np R(i1 + 4, k1) = "Error Absoluto Medio = " R(i1 + 4, k1 + 2) = aux(4) / np den = (Sqr(Application.SumSq(y_) / np) + Sqr (Application.SumSq(y_p) / np)) ^ 2 R(i1 + 5, k1) = "Coeficiente de Theil = " R(i1 + 5, k1 + 2) = R(i1 + 3, k1 + 2) / den R(i1 + 6, k1) = "sesgo (" R(i1 + 6, k1 + 2) = ((Application.Average(y_ ) - Application.Average(y_p)) ^ 2) / den R(i1 + 7, k1) = "dispersión (" R(i1 + 7, k1 + 2) = ((Application.StDevP(y_) - Application.StDevP(y_p)) ^ 2) / den R(i1 + 8, k1) = "correlación (" R(i1 + 8, k1 + 2) = 2 * (1 - Application.Cor rel(y_, y_p)) * _ Application.StDevP(y_) * Application.StDevP(y_p) / den For j1 = 6 To 8 R(i1 + j1, k1) = R(i1 + j1, k1) & Format ((R(i1 + j1, k1 + 2) / _ R(i1 + 5, k1 + 2)) * 10 0, "###0.00") & "%) = " Next j1 End If Call M1_ESCRIPTURA(4, "Predicciones 'ex-post'" & IIf(i2 <> 1, " (cont.)", "") & tit, aux) Next i2 End Sub Private Sub M1_05(opcio As Integer)

Page 38: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

37

'''''''''''''''''''''' 'RESTRICCIONS LINEALS' '''''''''''''''''''''' Dim a() As Double, aux(1 To 3), br() As Double, er_ es() As Double, Estim() As Boolean, _ fr() As Double, gln() As Integer, irest As Inte ger, i1 As Integer, i2 As Integer, _ j1 As Integer, n_r() As String, tit As String Call C_RESTRICCIONES_1(0, IXPX, a, br, er_es, Estim , fr, gln, irest, n_r) If SORTIR Then SORTIR = False If irest <= 1 Then Exit Sub Else irest = irest - 1 End If '''''''''''''''''''''''''''''''''''''''''''''''''' 'Calcula l'amplada de columna per a la restricció' '''''''''''''''''''''''''''''''''''''''''''''''''' aux(1) = 0 aux(3) = 1 For i1 = 1 To irest If Estim(i1) Then aux(3) = 0 Exit For End If Next i1 For i1 = 1 To irest If Len(n_r(i1)) > aux(1) Then i2 = i1 aux(1) = Len(n_r(i1)) End If Next i1 With Cells(1, 11) aux(2) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = n_r(i2) .Columns.AutoFit aux(1) = .ColumnWidth .Clear .ColumnWidth = aux(2) End With For i1 = 5 To 0 Step -1 If aux(1) > i1 * 9.57 Then Exit For Next i1 aux(2) = Application.max(i1 + 1, 1) aux(1) = "test" ReDim R(1 To irest + 2, 1 To aux(2) + 3) R(1, 1) = "Restricción" R(1, aux(2) + 1) = "Valor F" R(1, aux(2) + 2) = "gl" R(1, aux(2) + 3) = "Prob > F" For i1 = 1 To irest R(i1 + 2, 1) = n_r(i1) R(i1 + 2, aux(2) + 1) = fr(i1) / S2 R(i1 + 2, aux(2) + 2) = Format(gln(i1), "###,0" ) & " y " & Format(N - k, "###,0") R(i1 + 2, aux(2) + 3) = Application.FDist(R(i1 + 2, aux(2) + 1), gln(i1), N - k) R(i1 + 2, aux(2) + 3) = IIf(R(i1 + 2, aux(2) + 3) < 0.0001, "< 0,0001", R(i1 + 2, aux(2) + 3)) Next i1 If NPES <> 0 Then tit = " (Variable de Ponderación : " & LVAR(NPES, 1) & ")" Else tit = "" Call M1_ESCRIPTURA(5, "RESTRICCIONES LINEALES " & t it, aux) aux(1) = "estim" For i2 = 1 To irest aux(3) = 1 If Estim(i2) Then If i2 < irest Then If Estim(i2 + 1) Then aux(3) = 0 End If If (k > 6 And k <= 9) And i2 = 4 Then aux(3) = 1 If (k > 9 And k <= 15) And i2 = 3 Then aux(3 ) = 1 If k > 15 Then If i2 = 2 Or i2 = 4 Then aux(3) = 1 End If ReDim R(1 To k + 4, 1 To 7) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "err. es." & Chr(10) & "Parámetro" R(1, 4) = "Valor t"

Page 39: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

38

R(1, 5) = "Prob |t|" R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.=" & Format(SIG, "0.00") & ")" For i1 = 1 To k R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & ")" R(i1 + 2, 2) = br(i1, i2) If er_es(i1, i2) <> 0 Then R(i1 + 2, 3) = er_es(i1, i2) R(i1 + 2, 4) = R(i1 + 2, 2) / R(i1 + 2, 3) R(i1 + 2, 5) = Application.TDist(Abs( R(i1 + 2, 4)), GL(2), 2) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0 001, "< 0,0001", R(i1 + 2, 5)) R(i1 + 2, 6) = R(i1 + 2, 2) - Applica tion.TInv(SIG, GL(2)) * R(i1 + 2, 3) R(i1 + 2, 7) = R(i1 + 2, 2) + Applica tion.TInv(SIG, GL(2)) * R(i1 + 2, 3) End If Next i1 R(k + 3, 1) = "Var. Exp. =" R(k + 3, 6) = "Var. no Exp. =" R(k + 4, 1) = Chr(214) & "ECM = " R(k + 4, 3) = "R" & Chr(178) & " = " R(k + 4, 6) = "R" & Chr(178) & "corr. = " R(k + 3, 2) = a(1, i2) R(k + 3, 7) = a(2, i2) R(k + 4, 2) = a(3, i2) R(k + 4, 4) = a(4, i2) R(k + 4, 7) = a(5, i2) Call M1_ESCRIPTURA(5, "ESTIMACIÓN RESTRINGID A: " & n_r(i2) & tit, aux) End If Next i2 End Sub Private Sub M1_06(opcio As Integer) ''''''''''''''''''''' 'MULTICOL·LINEALITAT' ''''''''''''''''''''' Dim aux(1 To 1), i1 As Integer, j1 As Integer, k1 A s Integer If k <= 15 Then For i1 = 1 To 5 OPT(6, i1) = True Next i1 End If If k > 15 Then OPT(0, 0) = 5 With C2_Varis .Aceptar.Top = 90 .Cancelar.Top = 90 .Caption = "Modelos de Regresión: Multicolinea lidad" .c01.Caption = "Matriz de correlaciones (varia bles)" .c01.Value = False .c02.Caption = "Matriz de correlaciones (parám etros)" .c02.Value = False .c03.Caption = "Factores inflación varianza" .c03.Enabled = False .c04.Caption = "Números de condición y valores propios" .c04.Enabled = False .c05.Caption = "Proporción de varianza asociad a al valor propio" .c05.Value = False .Frame0.Height = 80 With .MultiPage1 .Height = 90 '85 .Style = fmTabStyleNone .Value = 0 End With .Height = 135 .Show End With If SORTIR Then SORTIR = False Unload C2_Varis End If '''''''''''''''''''''''''''''''''''''''''''' 'Matriu de correlacions entre les variables' '''''''''''''''''''''''''''''''''''''''''''' If OPT(6, 1) Or OPT(6, 3) Or OPT(6, 4) Or OPT(6, 5) Then Dim den As Double, num1 As Double, num2 As Doubl e ReDim corr_v(1 To k - IC + 1, 1 To k - IC + 1) A s Double For i1 = 1 To k - IC + 1 For j1 = i1 + 1 To k - IC + 1 num1 = XPX(i1 + IC, j1 + IC)

Page 40: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

39

If IC = 1 Then num2 = (SUMS(i1 + IC, 1) * SUMS(j1 + IC, 1) * NTPES) - (SUMS(i1 + IC, 1) * X PX(1, j1 + IC)) - (SUMS(j1 + IC, 1) * XPX(1, i1 + IC)) Else num2 = 0 den = SUMS(i1 + IC, IIf(IC = 1, 3, 2)) * SUMS(j1 + IC, IIf(IC = 1, 3, 2)) corr_v(i1, j1) = (num1 + num2) / Sqr(den ) If i1 <> j1 Then corr_v(j1, i1) = corr_v (i1, j1) Next j1 corr_v(i1, i1) = 1 Next i1 If OPT(6, 1) Then Call M1_ESCRIPTURA_1(61, corr_ v, B, "MATRIZ DE CORRELACIONES" & IIf(IC = 1, "", " NO CENTRADA") & " (VARIABLES)") End If ''''''''''''''''''''''''''''''''''''''''''''' 'Matriu de correlacions entre els paràmetres' ''''''''''''''''''''''''''''''''''''''''''''' If OPT(6, 2) Then ReDim corr_p(1 To k, 1 To k) As Double For i1 = 1 To k For j1 = i1 + 1 To k corr_p(i1, j1) = IXPX(i1, j1) / Sqr(IXP X(i1, i1) * IXPX(j1, j1)) If i1 <> j1 Then corr_p(j1, i1) = corr_ p(i1, j1) Next j1 corr_p(i1, i1) = 1 Next i1 Call M1_ESCRIPTURA_1(62, corr_p, B, "MATRIZ DE CORRELACIONES (PARÁMETROS)") End If ''''' 'FIV' ''''' If OPT(6, 3) Then ReDim fiv(1 To k - IC + 1, 1 To k - IC + 1) As D ouble, R(1 To k - IC + 1, 1 To 2) For i1 = 1 To k - IC For j1 = 1 To k - IC fiv(i1, j1) = corr_v(i1, j1) Next j1 Next i1 Call C_G2SWEEP(1, 0, fiv, N, k - IC + 1, 0.00000 001, False) R(1, 1) = "Variable" R(1, 2) = "F.I.V" For i1 = 1 To k - IC R(i1 + 1, 1) = LVAR(i1 + IC, 2) R(i1 + 1, 2) = fiv(i1, i1) Next i1 If k > 34 Then aux(1) = 1 Call M1_ESCRIPTURA(0, "FACTOR INFLACIÓN VARIANZA ", aux) End If '''''''''''''''''''''''''''''''''''''''''''' 'Nombre de condició i proporcions variància' '''''''''''''''''''''''''''''''''''''''''''' If OPT(6, 4) Or OPT(6, 5) Then Dim noint As Boolean For j1 = 1 To IIf(IC = 1, 2, 1) If j1 = 1 Then noint = False Else noint = Tr ue k1 = IIf(j1 = 1, k, k - 1) ReDim R(1 To k1 + 1, 1 To 3), valp(1 To k1) As Double, varp(1 To k1, 1 To k1) As Double Call M1_06_1(valp, varp, corr_v, 0, N, k1, n oint) R(1, 1) = "Orden" R(1, 2) = "Valor Propio" R(1, 3) = "Indice" For i1 = 1 To k1 R(i1 + 1, 1) = "lambda" & Str(i1) R(i1 + 1, 2) = valp(i1) R(i1 + 1, 3) = Sqr(valp(1) / valp(i1)) Next i1 If k1 > 15 Then aux(1) = 1 If OPT(6, 4) Then Call M1_ESCRIPTURA(0, "NÚM ERO DE CONDICIÓN (" & IIf(noint = 0, "NO ", "") & "CENTRADO)", aux) If OPT(6, 5) Then If Not noint Then Call M1_ESCRIPTURA_1(63 , varp, valp, "PROPORCION DE VARIANZA ASOCIADA AL V ALOR PROPIO (NO CENTRADA)") If noint Then Call M1_ESCRIPTURA_1(64, va rp, valp, "PROPORCION DE VARIANZA ASOCIADA AL VALOR PROPIO (CENTRADA)") End If

Page 41: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

40

Next j1 End If End Sub Sub M1_06_1(valp, varp, corr_v, opcio As Integer, n obs, nvars, noint) 'opcio=0 entra de la regressió 'opcio=1 entra de HECKMAN 'noint=0 inclou el terme independent en els càlculs dels valors propis 'noint=1 no inclou el terme independent en els càlc uls dels valors propis, només opera si l'estimació té terme independent ''''''''''''''''''''''''''''''''''' 'INDICADORS DE MULTICOL·LINEALITAT' ''''''''''''''''''''''''''''''''''' Dim aux(1 To 2) As Double, b_ As Double, c_ As Doub le, f_ As Double, g_ As Double, h_ As Double, hh_ A s Double, _ i1 As Integer, i3 As Long, j1 As Integer, k1 As Integer, l As Integer, l1 As Integer, m1 As Intege r, _ p_ As Double, r_ As Double, s_ As Double ReDim e_(1 To nvars) As Double, v(1 To nvars, 1 To nvars) As Double, _ z(1 To nvars + 1, 1 To nvars + 1) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' 'Calcula la matriu XPX estandaritzada (longitud uni tat)=z ' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' If Not noint Then For i3 = 1 To nobs For j1 = 1 To nvars If opcio = 0 Then aux(1) = Sqr(XY(i3, j1 ) ^ 2 / XPX(j1, j1)) If opcio = 1 Then aux(1) = Sqr(XY22(i3, j1) ^ 2 / XPX(j1, j1)) For k1 = 1 To nvars If opcio = 0 Then aux(2) = Sqr(XY(i3 , k1) ^ 2 / XPX(k1, k1)) If opcio = 1 Then aux(2) = Sqr(XY22( i3, k1) ^ 2 / XPX(k1, k1)) z(j1, k1) = z(j1, k1) + (aux(1) * au x(2) * PES(i3)) Next k1 Next j1 Next i3 Else For j1 = 1 To nvars For k1 = 1 To nvars z(j1, k1) = corr_v(j1, k1) Next k1 Next j1 End If ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''' 'Algoritme de "tridiagonalització" de la matriu z ( TRED2)' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''' For i1 = 1 To nvars For j1 = 1 To i1 v(i1, j1) = z(i1, j1) Next j1 Next i1 For i1 = nvars To 2 Step -1 l = i1 - 2 f_ = v(i1, i1 - 1) g_ = 0 For k1 = 1 To l g_ = g_ + v(i1, k1) ^ 2 Next k1 h_ = g_ + f_ ^ 2 l = l + 1 If f_ >= 0 Then g_ = -Sqr(h_) Else g_ = Sqr(h_) If f_ >= 0 Then e_(i1) = -Sqr(h_) Else e_(i1) = Sqr(h_) h_ = h_ - f_ * g_ v(i1, i1 - 1) = f_ - g_ f_ = 0 For j1 = 1 To l v(j1, i1) = v(i1, j1) / h_ g_ = 0 For k1 = 1 To j1 g_ = g_ + v(j1, k1) * v(i1, k1) Next k1 For k1 = j1 + 1 To l g_ = g_ + v(k1, j1) * v(i1, k1) Next k1 e_(j1) = g_ / h_ f_ = f_ + g_ * v(j1, i1) Next j1 hh_ = f_ / (h_ + h_)

Page 42: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

41

For j1 = 1 To l f_ = v(i1, j1) g_ = e_(j1) - hh_ * f_ e_(j1) = e_(j1) - hh_ * f_ For k1 = 1 To j1 v(j1, k1) = v(j1, k1) - f_ * e_(k1) - g _ * v(i1, k1) Next k1 Next j1 valp(i1) = h_ Next i1 valp(1) = 0 e_(1) = 0 For i1 = 1 To nvars l = i1 - 1 If valp(i1) <> 0 Then For j1 = 1 To l g_ = 0 For k1 = 1 To l g_ = g_ + v(i1, k1) * v(k1, j1) Next k1 For k1 = 1 To l v(k1, j1) = v(k1, j1) - g_ * v(k1, i 1) Next k1 Next j1 End If valp(i1) = v(i1, i1) v(i1, i1) = 1 For j1 = 1 To l v(i1, j1) = 0 v(j1, i1) = 0 Next j1 Next i1 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''' 'Algoritme de càlcul dels valors i vectors propis ( TQL2)' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''' For i1 = 2 To nvars e_(i1 - 1) = e_(i1) Next i1 e_(nvars) = 0 b_ = 0 f_ = 0 For l1 = 1 To nvars h_ = 0.0000000001 * (Abs(valp(l1)) + Abs(e_(l1) )) If b_ < h_ Then b_ = h_ For m1 = l1 To nvars If Abs(e_(m1)) <= b_ Then GoTo CONT Next m1 CONT: If m1 = l1 Then GoTo ROOT g_ = valp(l1) p_ = (valp(l1 + 1) - g_) / (2 * e_(l1)) r_ = Sqr(p_ ^ 2 + 1) valp(l1) = e_(l1) / IIf(p_ < 0, p_ - r_, p_ + r _) h_ = g_ - valp(l1) For i1 = l1 + 1 To nvars valp(i1) = valp(i1) - h_ Next i1 f_ = f_ + h_ p_ = valp(m1) c_ = 1 s_ = 0 For i1 = m1 - 1 To l1 Step -1 g_ = c_ * e_(i1) h_ = c_ * p_ If Abs(p_) >= Abs(e_(i1)) Then c_ = e_(i1) / p_ r_ = Sqr(c_ ^ 2 + 1) e_(i1 + 1) = s_ * p_ * r_ s_ = c_ / r_ c_ = 1 / r_ Else c_ = p_ / e_(i1) r_ = Sqr(c_ ^ 2 + 1) e_(i1 + 1) = s_ * e_(i1) * r_ s_ = 1 / r_ c_ = c_ / r_ End If p_ = c_ * valp(i1) - s_ * g_ valp(i1 + 1) = h_ + s_ * (c_ * g_ + s_ * va lp(i1)) For k1 = 1 To nvars h_ = v(k1, i1 + 1)

Page 43: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

42

v(k1, i1 + 1) = s_ * v(k1, i1) + c_ * h _ v(k1, i1) = c_ * v(k1, i1) - s_ * h_ Next k1 Next i1 e_(l1) = s_ * p_ valp(l1) = c_ * p_ If Abs(e_(l1)) > b_ Then GoTo CONT ROOT: valp(l1) = valp(l1) + f_ Next l1 For i1 = 1 To nvars k1 = i1 p_ = valp(i1) For j1 = i1 + 1 To nvars If valp(j1) > p_ Then k1 = j1 p_ = valp(j1) End If Next j1 If k1 <> i1 Then valp(k1) = valp(i1) valp(i1) = p_ For j1 = 1 To nvars p_ = v(j1, i1) v(j1, i1) = v(j1, k1) v(j1, k1) = p_ Next j1 End If Next i1 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''' 'Determinació de les proporcions de variància assoc iades als valors propis' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''' Call C_G2SWEEP(1, 0, z, nobs, nvars + 1, 0.00000001 , False) For i1 = 1 To nvars For j1 = 1 To nvars varp(i1, j1) = ((v(j1, i1) ^ 2) / valp(i1)) / z(j1, j1) Next j1 Next i1 End Sub Private Sub M1_07(opcio As Integer) '''''''''''''''''''''''''''' 'CONTRASTOS D'ESPECIFICACIÓ' '''''''''''''''''''''''''''' Dim i1 As Integer, j1 As Integer, tit1 As String ReDim tests(1 To 9) With C2_Varis .Aceptar.Top = 135 .Cancelar.Top = 135 .Caption = "Modelos de Regresión: Contrastes de e specificación" With .MultiPage1 .Height = 130 .Style = fmTabStyleNone .Value = 2 End With If NPES <> 0 Then .Label74.Enabled = False .Label75.Enabled = False .test74.Enabled = False .test75.Enabled = False .test76.Enabled = False .test77.Enabled = False .test78.Enabled = False .test79.Enabled = False End If If CInt(N / 3) < 2 * k Then With .test74 .Enabled = False .Value = False End With End If If T_DADES = "CS" Then .Label75.Enabled = False .test77.Enabled = False .test78.Enabled = False .test79.Enabled = False End If .Height = 180

Page 44: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

43

.Show End With Unload C2_Varis If SORTIR Then SORTIR = False Exit Sub Else j1 = 0 For i1 = 1 To 9 If tests(i1) Then j1 = j1 + 1 Next i1 If j1 = 0 Then SORTIR = False Exit Sub End If End If Dim aut As Boolean, avisBP As Boolean, chow As Bool ean, dim1 As Integer, goldfeld As Boolean, het As B oolean, _ it As Integer, i2 As Integer, i3 As Integer, i4 As Integer, j2 As Integer, nomsvar() dim1 = 0 For i1 = 1 To IIf(T_DADES = "CS", 7, 9) If i1 = 1 Or i1 = 6 Or i1 = 7 Then If tests(i1) Then dim1 = dim1 + 1 ElseIf i1 = 2 Then If tests(i1) Then dim1 = dim1 + 3 ElseIf i1 = 3 Or i1 = 8 Then If tests(i1) Then dim1 = dim1 + 4 ElseIf i1 = 4 Then If tests(i1) Then dim1 = dim1 + k - IC ElseIf i1 = 5 Then If tests(i1) Then dim1 = dim1 + 5 ElseIf i1 = 9 Then If tests(i1) Then dim1 = dim1 + (2 * Applic ation.min(Int(N / 18), 6)) End If Next i1 ReDim gl1(1 To dim1) As Integer, gl2(1 To dim1) As Integer, test(1 To dim1, 1 To 2) As Double, _ tit(1 To dim1, 1 To 2) As String, T_Err(1 To dim1) As Boolean i2 = 0 If tests(1) Then i2 = i2 + 1 T_Err(i2) = False Call M1_07_1(test(i2, 1), gl1(i2), T_Err(i2)) tit(i2, 1) = "Normalidad" tit(i2, 2) = "Bera-Jarque" End If If tests(2) Then For i3 = 1 To 3 i2 = i2 + 1 T_Err(i2) = False Call M1_07_2(test(i2, 2), gl1(i2), gl2(i2), i3, T_Err(i2)) If T_Err(i2) Then i2 = i2 - 1 Exit For End If If i3 = 1 Then tit(i2, 1) = "Linealidad" tit(i2, 2) = "Reset(" & i3 + 1 & ")" Next i3 End If If tests(3) Then Call M1_07_3_1(chow) If chow Then it = i2 + 1 For i3 = 1 To UBound(P_CHOW) i2 = i2 + 1 T_Err(i2) = False Call M1_07_3(test(i2, 2), gl1(i2), gl2(i2 ), P_CHOW(i3), T_Err(i2)) If T_Err(i2) Then i2 = i2 - 1 Else If i3 = 1 Then tit(i2, 1) = "Permanencia Estructur al" Else If i2 = it Then tit(i2, 1) = "Perma nencia Estructural" End If tit(i2, 2) = "Chow(p=" & P_CHOW(i3) & ")" End If Next i3 End If End If If tests(4) Then

Page 45: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

44

Call M1_07_45(tests(4), "GQ", 1, VARS) If tests(4) Then it = i2 + 1 For i3 = 1 To UBound(VARS) i2 = i2 + 1 T_Err(i2) = False Call M1_07_4(test(i2, 2), gl1(i2), gl2(i2 ), VARS(i3), T_Err(i2), goldfeld) If goldfeld Then If T_Err(i2) Then i2 = i2 - 1 Else If i3 = 1 Then tit(i2, 1) = "Homoscedasticidad" het = True Else If i2 = it Then tit(i2, 1) = "Homoscedasticid ad" het = True End If End If tit(i2, 2) = "Goldfeld-Quandt(" & L VAR(VARS(i3), 2) & ")" End If Else i2 = i2 - 1 Exit For End If Next i3 End If End If If tests(5) Then i4 = 0 For i3 = 1 To 5 Call M1_07_45(tests(5), "BP", i3, VARS) If tests(5) Then i2 = i2 + 1 T_Err(i2) = False Call M1_07_5(test(i2, 1), test(i2, 2), gl 1(i2), gl2(i2), T_Err(i2)) If T_Err(i2) Then i2 = i2 - 1 Else If i3 = 1 Then If Not het Then tit(i2, 1) = "Homoscedasticidad" het = True End If End If If UBound(VARS) = 1 Then tit(i2, 2) = "Breusch-Pagan (" & LV AR(VARS(1), 1) & ")" Else i4 = i4 + 1 tit(i2, 2) = "Breusch-Pagan (" & St ring(i4, "*") & ")" ReDim Preserve nomsvar(1 To i4) nomsvar(i4) = "(" & String(i4, "*") & ") En la regresión auxiliar intervienen: Constan te, " For i1 = 1 To UBound(VARS) nomsvar(i4) = nomsvar(i4) & LVA R(VARS(i1), 1) & IIf(i1 < UBound(VARS), ",", ".") Next i1 End If End If End If If Not P_BP Then Exit For Next i3 If i4 = 0 Then avisBP = False Else avisBP = True End If If tests(6) Then i2 = i2 + 1 T_Err(i2) = False Call M1_07_6(test(i2, 1), test(i2, 2), gl1(i2), gl2(i2), T_Err(i2)) If T_Err(i2) Then i2 = i2 - 1 Else tit(i2, 2) = "White" If Not het Then tit(i2, 1) = "Homoscedasticid ad" End If End If If tests(7) Then i2 = i2 + 1 T_Err(i2) = False Call M1_07_7(test(i2, 2)) tit(i2, 1) = "No Autocorrelación" tit(i2, 2) = "Durbin-Watson" aut = True End If If tests(8) Then

Page 46: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

45

it = i2 + 1 For i3 = 1 To 4 i2 = i2 + 1 T_Err(i2) = False Call M1_07_8(test(i2, 1), test(i2, 2), gl1(i 2), gl2(i2), i3, T_Err(i2)) If T_Err(i2) Then i2 = i2 - 1 Else If Not aut Then If i2 = it Then tit(i2, 1) = "No Autocorrelación" aut = True End If End If tit(i2, 2) = "Godfrey AR(" & gl1(i2) & ") " End If Next i3 End If If tests(9) Then i4 = Int(N / 18) If i4 > 6 Then i4 = 6 If i4 <> 0 Then it = i2 + 1 For i3 = 1 To i4 For j2 = 1 To 2 i2 = i2 + 1 T_Err(i2) = False Call M1_07_9(test(i2, 1), gl1(i2), i3 , j2, N, T_Err(i2)) If Not aut Then If i2 = it Then tit(i2, 1) = "No Autocorrelació n" aut = True End If End If tit(i2, 2) = IIf(j2 = 1, "Box-Pierce( " & gl1(i2) & ")", "Ljung-Box(" & gl1(i2) & ")") Next j2 Next i3 End If End If If i2 = 0 Then Exit Sub If Not avisBP Then ReDim nomsvar(1 To 1) nomsvar(1) = "" End If ReDim R(1 To i2 + 2 + IIf(nomsvar(1) = "", 0, UBoun d(nomsvar)), 1 To 10) R(1, 1) = "Hipótesis Nula" R(1, 3) = "Test" R(1, 5) = "Versión c" & Chr(178) R(1, 8) = "Versión F" R(2, 5) = "Valor c" & Chr(178) R(2, 6) = "gl" R(2, 7) = "Prob > c" & Chr(178) R(2, 8) = "Valor F" R(2, 9) = "gl" R(2, 10) = "Prob > F" For i1 = 1 To i2 R(i1 + 2, 1) = tit(i1, 1) R(i1 + 2, 3) = tit(i1, 2) If Left(R(i1 + 2, 3), 5) <> "Reset" And Left(R( i1 + 2, 3), 4) <> "Chow" And _ Left(R(i1 + 2, 3), 8) <> "Goldfeld" And Left (R(i1 + 2, 3), 6) <> "Durbin" Then If Not T_Err(i1) Then R(i1 + 2, 5) = test(i1, 1) R(i1 + 2, 6) = gl1(i1) R(i1 + 2, 7) = Application.ChiDist(test(i 1, 1), gl1(i1)) R(i1 + 2, 7) = IIf(R(i1 + 2, 7) < 0.0001, "< 0,0001", R(i1 + 2, 7)) Else R(i1 + 2, 5) = "----------" R(i1 + 2, 6) = "----------" R(i1 + 2, 7) = "----------" End If Else R(i1 + 2, 5) = "----------" R(i1 + 2, 6) = "----------" R(i1 + 2, 7) = "----------" End If If Left(R(i1 + 2, 3), 4) <> "Bera" And Left(R(i 1 + 2, 3), 6) <> "Durbin" And _ Left(R(i1 + 2, 3), 10) <> "Box-Pierce" And L eft(R(i1 + 2, 3), 9) <> "Ljung-Box" Then If Not T_Err(i1) Then R(i1 + 2, 8) = test(i1, 2) R(i1 + 2, 9) = gl1(i1) & " y " & gl2(i1) R(i1 + 2, 10) = Application.FDist(test(i1 , 2), gl1(i1), gl2(i1)) R(i1 + 2, 10) = IIf(R(i1 + 2, 10) < 0.000 1, "< 0,0001", R(i1 + 2, 10))

Page 47: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

46

Else R(i1 + 2, 8) = "----------" R(i1 + 2, 9) = "----------" R(i1 + 2, 10) = "----------" End If ElseIf Left(R(i1 + 2, 3), 4) = "Bera" Or Left(R (i1 + 2, 3), 10) = "Box-Pierce" Or _ Left(R(i1 + 2, 3), 9) = "Ljung-Box" Then R(i1 + 2, 8) = "----------" R(i1 + 2, 9) = "----------" R(i1 + 2, 10) = "----------" ElseIf Left(R(i1 + 2, 3), 6) = "Durbin" Then R(i1 + 2, 9) = "DW = " & Format(test(i1, 2), "#0.000") End If Next i1 If NPES <> 0 Then tit1 = " (Variable de Ponderació n: " & LVAR(NPES, 1) & ")" Else tit1 = "" Call M1_ESCRIPTURA(7, "CONTRASTES DE ESPECIFICACIÓN " & tit1, nomsvar) End Sub Private Sub M1_07_1(test_a, gl_1, errortest) ''''''''''''''''''''''''' 'CONTRAST DE BERA-JARQUE' ''''''''''''''''''''''''' Dim i1 As Long, j1 As Integer, s3 As Double, s4 As Double '''''''''''''''''''''''''''''''''''''' 'Determina l'asimetria i l'apuntament' '''''''''''''''''''''''''''''''''''''' For i1 = 1 To N s3 = s3 + (E(i1) ^ 3) s4 = s4 + (E(i1) ^ 4) Next i1 ''''''''''''''''''''' 'Calcula el contrast' ''''''''''''''''''''' gl_1 = 2 test_a = N * ((Sqr(N) * s3 / Sq(2) ^ (3 / 2)) ^ 2 / 6 + ((N * s4 / Sq(2) ^ 2) - 3) ^ 2 / 24) If test_a < 0 Then errortest = True End Sub Private Sub M1_07_2(test_f, gl_1, gl_2, i2, errorte st) '''''''''''''''' 'CONTRAST RESET' '''''''''''''''' Dim cl As Integer, i1 As Integer, i3 As Long, j1 As Integer, k1 As Integer, vne As Double ReDim m(1 To k + i2 + 1, 1 To k + i2 + 1) As Double , scl(1 To k + i2) As Double, _ xy_(1 To k + i2 + 1) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' 'Determina la matriu ampliada de productes creuats' ''''''''''''''''''''''''''''''''''''''''''''''''''' For i3 = 1 To N For j1 = 1 To k xy_(j1) = XY(i3, j1) Next j1 For j1 = 1 To i2 xy_(k + j1) = YHAT(i3) ^ (j1 + 1) Next j1 xy_(k + i2 + 1) = XY(i3, k + 1) For j1 = 1 To k + i2 + 1 For k1 = j1 To k + i2 + 1 m(j1, k1) = m(j1, k1) + (xy_(j1) * xy_( k1) * PES(i3)) Next k1 Next j1 Next i3 For j1 = 1 To k + i2 + 1 For k1 = j1 + 1 To k + i2 + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' 'Calcula la regressió auxiliar i verifica possibles combinacions lineals exactes' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' Call C_G2SWEEP(1, IC, m, N, k + i2 + 1, 0.000000000 00001, False)

Page 48: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

47

For i1 = 1 To k + i2 For j1 = 1 To k + i2 scl(i1) = scl(i1) + m(i1, j1) Next j1 Next i1 cl = 0 For i1 = 1 To k + i2 If scl(i1) = 0 Then cl = cl + 1 Next i1 ''''''''''''''''''''' 'Calcula el contrast' ''''''''''''''''''''' vne = m(k + i2 + 1, k + i2 + 1) gl_1 = i2 - cl gl_2 = N - (k + gl_1) test_f = ((Sq(2) - vne) / gl_1) / (vne / gl_2) If test_f < 0 Then errortest = True End Sub Private Sub M1_07_3_1(chow) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''' 'AUXILIAR PER A DETERMINAR ELS PUNTS AMB QUÈ CALCUL AR EL CONTRAST DE CHOW' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''' Dim avis As String avis = " Puede señalar un punto de corte en cada cu adro. Si no rellena un" & Chr(10) & _ " cuadro no se efectuará el contraste para e se punto y los siguientes." & Chr(10) & _ " Recuerde que el tamaño muestral que está u tilizando es " & Format(N, "###,0") & "." & Chr(10) & Chr(10) & _ " El punto de corte indicado determina el ti po contraste efectuado:" & Chr(10) & _ " se utilizarán dos submuestras de comparaci ón cuando su tamaño" & Chr(10) & _ " sea igual o superior al triple de regresor es y una única muestra" & Chr(10) & _ " de comparación, cuando una de ellas incump la tal condición." chow = True With C2_Varis .Caption = "Modelos de regresión: Test de Chow" .Label710.Caption = avis With .MultiPage1 .Style = fmTabStyleNone .Value = 3 End With .pchow1.Value = Int(N / 2) End With ERR_LEC = True SORTIR = False Do While ERR_LEC C2_Varis.Show If SORTIR Then ERR_LEC = False Loop Unload C2_Varis If SORTIR Then chow = False SORTIR = False End If End Sub Private Sub M1_07_3(test_f, gl_1, gl_2, break, erro rtest) '''''''''''''''''' 'CONTRAST DE CHOW' '''''''''''''''''' Dim i1 As Integer, i2 As Integer, i3 As Integer, j1 As Integer, j2 As Integer, _ m() As Double, n1 As Integer, vne(1 To 2) As Do uble ReDim xy_(1 To k + 1) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' 'Determina la matriu xy_ ,i2=2 test clàssic (dues r egressions)' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' For i2 = 1 To IIf((break - 1) >= (3 * k) And (N - b reak + 1) >= (3 * k), 2, 1) If (break - 1) >= (3 * k) And (N - break + 1) > = (3 * k) Then i3 = IIf(i2 = 1, 0, break) n1 = IIf(i2 = 1, break, N - break) Else i3 = IIf(break - 1 < 3 * k, break - 1, 0)

Page 49: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

48

n1 = IIf(break - 1 < 3 * k, N - break + 1, break - 1) End If ReDim m(1 To k + 1, 1 To k + 1) For i1 = 1 To n1 For j1 = 1 To k xy_(j1) = XY(i1 + i3, j1) Next j1 xy_(k + 1) = XY(i1 + i3, k + 1) For j1 = 1 To k + 1 For j2 = j1 To k + 1 m(j1, j2) = m(j1, j2) + (xy_(j1) * xy_(j2) * PES(i1 + i3)) Next j2 Next j1 Next i1 For j1 = 1 To k + 1 For j2 = j1 + 1 To k + 1 m(j2, j1) = m(j1, j2) Next j2 Next j1 ''''''''''''''''''''''''''''''' 'Calcula la regressió auxiliar' ''''''''''''''''''''''''''''''' Call C_G2SWEEP(1, IC, m, n1, k + 1, 0.00000001, False) vne(i2) = m(k + 1, k + 1) Next i2 ''''''''''''''''''''' 'Calcula el contrast' ''''''''''''''''''''' gl_1 = IIf((break - 1) >= (3 * k) And (N - break + 1) >= (3 * k), k, N - n1) gl_2 = IIf((break - 1) >= (3 * k) And (N - break + 1) >= (3 * k), N - (2 * k), n1 - k) test_f = IIf((break - 1) >= (3 * k) And (N - break + 1) >= (3 * k), _ ((Sq(2) - (vne(1) + vne(2))) / gl_1) / ((v ne(1) + vne(2)) / gl_2), _ ((Sq(2) - vne(1)) / gl_1) / (vne(1) / gl_2 )) If test_f <= 0 Then errortest = True End Sub Private Sub M1_07_45(test, nom, i3, VARS) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' 'AUXILIAR PER A DETERMINAR LES VARIABLES AMB QUÈ CA LCULAR GQ I BP' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' Dim avis As String, h As Single, h1 As Single, i1 A s Integer, i2 As Integer If nom = "GQ" Then avis = "Seleccione tantas variables como contras tes a calcular" ReDim v(1 To k - IC) As String For i1 = IC + 1 To k v(i1 - IC) = LVAR(i1, 2) Next i1 ElseIf nom = "BP" Then ReDim v(R_XY.Columns.Count - 2 - IIf(IY <> 0, 1, 0) - IIf(NPES <> 0, 1, 0)) As String avis = "Seleccione las variables explicativas de la regresión auxiliar" i2 = 0 For i1 = 1 To R_XY.Columns.Count If i1 <> NY And i1 <> IY And i1 <> NPES Then i2 = i2 + 1 v(i2 - 1) = LVAR(i1, 1) End If Next i1 End If h = Application.min(70, 11 * (UBound(v) + 1)) h1 = IIf(nom = "BP", 20, 0) test = True With C2_Varis .Aceptar.Top = h + 55 + h1 .Cancelar.Top = h + 55 + IIf(nom = "GQ", 0, 20) .Caption = "Modelos de regresión: " & IIf(nom = " GQ", "Test Goldfeld-Quandt", "Test Breusch-Pagan") & _ IIf(nom <> "gq" And i3 > 1, " (núm. " & i3 & ")", "") .Frame72.Height = h + 25 + h1 .Label721.Caption = avis .ListBox72.Height = h .ListBox72.List = v With .MultiPage1 .Height = h + 50 + h1 .Style = fmTabStyleNone .Value = 4

Page 50: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

49

End With If nom = "BP" Then .OtrosBP72.Visible = True If i3 = 5 Then .OtrosBP72.Enabled = False .OtrosBP72.Top = h + 25 End If .Height = h + 100 + h1 End With ERR_LEC = True SORTIR = False Do While ERR_LEC C2_Varis.Show If SORTIR Then ERR_LEC = False Loop Unload C2_Varis If SORTIR Then test = False If nom = "BP" Then P_BP = False SORTIR = False End If End Sub Private Sub M1_07_4(test_f, gl_1, gl_2, i2, errorte st, goldfeld) ''''''''''''''''''''''''''''' 'CONTRAST DE GOLDFELD-QUANDT' ''''''''''''''''''''''''''''' goldfeld = True Dim i1 As Long, i3 As Integer, j1 As Integer, j2 As Integer, k1 As Integer, m() As Double, p As Intege r, vne(1 To 2) As Double p = CInt(N / 3) 'Determina les observacions centrals a el iminar' Call C_ORDENA(1, i2, i2) 'Reordena en funció de la variable' ''''''''''''''''''''''''''''''''''''''''''''''''''' 'Determina la matriu ampliada de productes creuats' ''''''''''''''''''''''''''''''''''''''''''''''''''' For i3 = 1 To 2 ReDim m(1 To k + 1, 1 To k + 1) For i1 = IIf(i3 = 1, 1, N - p + 1) To IIf(i3 = 1, p, N) For j1 = 1 To k + 1 For j2 = j1 To k + 1 m(j1, j2) = m(j1, j2) + (XY(IND(i1, 1), j1) * XY(IND(i1, 1), j2) * PES(IND(i1, 1))) Next j2 Next j1 Next i1 For j1 = 1 To k + 1 For j2 = j1 + 1 To k + 1 m(j2, j1) = m(j1, j2) Next j2 Next j1 Call C_G2SWEEP(1, IC, m, p, k + 1, 0.00000001, False) 'Calcula les regressions auxiliars' vne(i3) = m(k + 1, k + 1) Next i3 gl_1 = p - k gl_2 = gl_1 test_f = vne(2) / vne(1) 'Calcula el contrast' If test_f < 0 Then errortest = True End Sub Private Sub M1_07_5(test_a, test_f, gl_1, gl_2, err ortest) ''''''''''''''''''''''''''' 'CONTRAST DE BREUSCH-PAGAN' ''''''''''''''''''''''''''' Dim cl As Integer, dim2 As Integer, i1 As Long, j1 As Integer, k1 As Integer, vne As Double, vtot As D ouble dim2 = UBound(VARS) + 2 ReDim m(1 To dim2, 1 To dim2) As Double, scl(1 To d im2 - 1) As Double, xy_(1 To dim2) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' 'Determina la matriu xy_ de la regressió auxiliar d el contrast' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' For i1 = 1 To N

Page 51: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

50

xy_(1) = 1 For j1 = 1 To dim2 - 2 xy_(j1 + 1) = R_XY.Rows(i1).Columns(VARS(j1 )) Next j1 xy_(dim2) = E(i1) ^ 2 For j1 = 1 To dim2 For k1 = j1 To dim2 m(j1, k1) = m(j1, k1) + (xy_(j1) * xy_( k1) * PES(i1)) Next k1 Next j1 Next i1 For j1 = 1 To dim2 For k1 = j1 + 1 To dim2 m(k1, j1) = m(j1, k1) Next k1 Next j1 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' 'Calcula la regressió auxiliar i verifica possibles combinacions lineals exactes' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' vtot = m(dim2, dim2) - ((m(1, dim2) ^ 2) / NTPES) Call C_G2SWEEP(1, 1, m, N, dim2, 0.00000001, False) vne = m(dim2, dim2) For i1 = 1 To dim2 - 1 For j1 = 1 To dim2 - 1 scl(i1) = scl(i1) + m(i1, j1) Next j1 Next i1 cl = 0 For i1 = 1 To dim2 - 1 If scl(i1) = 0 Then cl = cl + 1 Next i1 ''''''''''''''''''''' 'Calcula el contrast' ''''''''''''''''''''' gl_1 = dim2 - 2 - cl gl_2 = N - (gl_1 + 1) test_a = N * (vtot - vne) / vtot test_f = ((vtot - vne) / gl_1) / (vne / gl_2) If test_f < 0 Or test_a < 0 Then errortest = True End Sub Private Sub M1_07_5VELL(test_a, test_f, gl_1, gl_2, errortest) ''''''''''''''''''''''''''' 'CONTRAST DE BREUSCH-PAGAN' ''''''''''''''''''''''''''' Dim aux As Double, cl As Integer, dim2 As Integer, i1 As Long, j1 As Integer, k1 As Integer, _ m1 As Double, vne As Double, vtot As Double dim2 = UBound(VARS) + 2 ReDim m(1 To dim2, 1 To dim2) As Double, scl(1 To d im2 - 1) As Double, xy_(1 To dim2) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' 'Determina la matriu xy_ de la regressió auxiliar d el contrast' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' aux = Sq(2) / NTPES For i1 = 1 To N xy_(1) = 1 For j1 = 1 To dim2 - 2 xy_(j1 + 1) = R_XY.Rows(i1).Columns(VARS(j1 )) Next j1 xy_(dim2) = (E(i1) ^ 2) - aux For j1 = 1 To dim2 For k1 = j1 To dim2 m(j1, k1) = m(j1, k1) + (xy_(j1) * xy_( k1) * PES(i1)) Next k1 Next j1 Next i1 For j1 = 1 To dim2 For k1 = j1 + 1 To dim2 m(k1, j1) = m(j1, k1) Next k1 Next j1 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' 'Calcula la regressió auxiliar i verifica possibles combinacions lineals exactes' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''

Page 52: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

51

vtot = m(dim2, dim2) - ((m(1, dim2) ^ 2) / NTPES) Call C_G2SWEEP(1, 1, m, N, dim2, 0.00000001, False) vne = m(dim2, dim2) For i1 = 1 To dim2 - 1 For j1 = 1 To dim2 - 1 scl(i1) = scl(i1) + m(i1, j1) Next j1 Next i1 cl = 0 For i1 = 1 To dim2 - 1 If scl(i1) = 0 Then cl = cl + 1 Next i1 ''''''''''''''''''''' 'Calcula el contrast' ''''''''''''''''''''' gl_1 = dim2 - 2 - cl gl_2 = N - (gl_1 + 1) m1 = 0 For i1 = 1 To N m1 = m1 + ((((E(i1) ^ 2) - aux) ^ 2)) * PES(i1) Next i1 test_a = (vtot - vne) / (m1 / NTPES) test_f = ((vtot - vne) / gl_1) / (vne / gl_2) If test_f < 0 Or test_a < 0 Then errortest = True End Sub Private Sub M1_07_6(test_a, test_f, gl_1, gl_2, err ortest) ''''''''''''''''''' 'CONTRAST DE WHITE' ''''''''''''''''''' Dim cl As Integer, dim2 As Integer, i1 As Long, i2 As Integer, j1 As Integer, _ j2 As Integer, k1 As Integer, vne As Double, vt ot As Double k1 = IIf(IC = 1, 0, 1) dim2 = ((k + k1) * (k + k1 + 1) / 2) + 1 ReDim m(1 To dim2, 1 To dim2) As Double, scl(1 To d im2 - 1) As Double, xy_(1 To dim2) As Double For i1 = 1 To N xy_(1) = 1 For j1 = IC + 1 To k xy_(j1 + k1) = XY(i1, j1) '1a. part de xy_ (originals)' Next j1 For j1 = 1 To k - IC xy_(k + k1 + j1) = XY(i1, j1 + IC) ^ 2 '2a . part de xy_ (quadrats originals)' Next j1 i2 = 0 For j1 = 1 To k - IC - 1 For j2 = j1 + 1 To k - IC i2 = i2 + 1 xy_(k + k1 + k - IC + i2) = XY(i1, j1 + IC) * XY(i1, j2 + IC) '3a. part de xy_ (productes 2 a 2)' Next j2 Next j1 xy_(dim2) = E(i1) ^ 2 'Determina la 4a. part de xy_ (residus al quadrat)' For j1 = 1 To dim2 For j2 = j1 To dim2 m(j1, j2) = m(j1, j2) + (xy_(j1) * xy_( j2) * PES(i1)) 'Construeix la matriu de productes creuats' Next j2 Next j1 Next i1 For j1 = 1 To dim2 For j2 = j1 + 1 To dim2 m(j2, j1) = m(j1, j2) Next j2 Next j1 vtot = m(dim2, dim2) - ((m(1, dim2) ^ 2) / NTPES) Call C_G2SWEEP(1, 1, m, N, dim2, 0.00000001, False) 'regressió auxiliar i combinacions lineals exacte s' vne = m(dim2, dim2) cl = 0 For j1 = 1 To dim2 - 1 If m(1, j1) = 0 Then cl = cl + 1 Next j1 'For j1 = 1 To dim2 - 1

Page 53: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

52

'Debug.Print j1, m(1, j1), m(j1, 1) 'Next j1 gl_1 = dim2 - 2 - cl gl_2 = N - (gl_1 + 1) test_a = N * (vtot - vne) / vtot 'Calcula el contrast assimptòtic' test_f = ((vtot - vne) / gl_1) / (vne / gl_2) 'Calcula el contrast F' If test_f < 0 Or test_a < 0 Then errortest = True End Sub Private Sub M1_07_7(test) ''''''''''''''''''''''''''' 'C0NTRAST DE DURBIN-WATSON' ''''''''''''''''''''''''''' Dim i1 As Long test = 0 For i1 = 2 To N test = test + (E(i1) - E(i1 - 1)) ^ 2 Next i1 test = test / Sq(2) End Sub Private Sub M1_07_8(test_a, test_f, gl_1, gl_2, i2, errortest) ''''''''''''''''''''' 'CONTRAST DE GODFREY' ''''''''''''''''''''' Dim i1 As Long, j1 As Integer, k1 As Integer, vne A s Double, VT As Double ReDim m(1 To k + i2 + 1, 1 To k + i2 + 1) As Double , xy_(1 To k + i2 + 1) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''' 'Determina les X a la matriu auxiliar (retards dels residus)' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''' For i1 = 1 To N For j1 = 1 To k xy_(j1) = XY(i1, j1) Next j1 For j1 = 1 To i2 If i1 <= j1 Then xy_(k + j1) = 0 Else xy_(k + j1) = E(i1 - j1) Next j1 xy_(k + i2 + 1) = E(i1) For j1 = 1 To k + i2 + 1 For k1 = j1 To k + i2 + 1 m(j1, k1) = m(j1, k1) + (xy_(j1) * xy_( k1)) Next k1 Next j1 Next i1 For j1 = 1 To k + i2 + 1 For k1 = j1 + 1 To k + i2 + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 VT = Sq(2) Call C_G2SWEEP(1, IC, m, N, k + i2 + 1, 0.000000001 , False) 'Calcula la Regressió auxiliar' vne = m(k + i2 + 1, k + i2 + 1) gl_1 = i2 gl_2 = N - (k + i2) test_a = N * (VT - vne) / VT 'C alcula el contrast assimptotic' test_f = ((VT - vne) / gl_1) / (vne / gl_2) 'C alcula el contrast F' If test_f < 0 Or test_a < 0 Then errortest = True End Sub Private Sub M1_07_9(test_a, gl_1, i1, j1, T, errort est) ''''''''''''''''''''''''''''''''''' 'CONTRAST DE BOX-PIERCE, LJUNG-BOX' ''''''''''''''''''''''''''''''''''' Dim i2 As Integer, j2 As Integer ReDim rho(1 To 6 * i1) As Double ''''''''''''''''''''''' 'Calcula els contrasts' '''''''''''''''''''''''

Page 54: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

53

gl_1 = UBound(rho) For i2 = 1 To gl_1 rho(i2) = 0 For j2 = i2 + 1 To T rho(i2) = rho(i2) + (E(j2) * E(j2 - i2)) Next j2 rho(i2) = rho(i2) / Sq(2) Next i2 If j1 = 1 Then test_a = T * Application.SumSq(rho) Else test_a = 0 For j2 = 1 To gl_1 test_a = test_a + ((T + 2) * (rho(j2) ^ 2) / (T - j2)) Next j2 test_a = T * test_a End If If test_a < 0 Then errortest = True End Sub Private Sub M1_08(opcio As Integer) ''''''''''''''''''''''''''' 'ESTIMACIÓ ROBUSTA (WHITE)' ''''''''''''''''''''''''''' Dim aux(1 To 1, 1 To 1), auxi, i1 As Integer, i3 As Long, j1 As Integer, j2 As Integer, _ k1 As Integer, l1 As Integer, tit As String ReDim R(1 To k + 2, 1 To 7), xpox(1 To k, 1 To k) A s Double, varb(1 To k, 1 To k) As Double If k <= 18 Then OPT(8, 2) = True If k > 18 Then OPT(0, 0) = 6 With C2_Varis .Aceptar.Top = 45 .Cancelar.Top = 45 .Caption = "Modelos de Regresión: Estimación d e White" .c01.Caption = "Estimación de los parámetros" .c01.Locked = True .c02.Caption = "Matriz de varianzas y covarian zas" .c02.Value = False .c03.Visible = False .c04.Visible = False .c05.Visible = False .Frame0.Height = 35 With .MultiPage1 .Height = 45 .Style = fmTabStyleNone .Value = 0 End With .Height = 90 .Show End With If SORTIR Then SORTIR = False Unload C2_Varis End If R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "err. es." & Chr(10) & "Parámetro" R(1, 4) = "Valor t" R(1, 5) = "Prob |t|" R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" For j1 = 1 To k For j2 = j1 To k auxi = 0 For i3 = 1 To N auxi = auxi + (XY(i3, j1) * XY(i3, j2) * ((E(i3) * PES(i3)) ^ 2)) Next i3 xpox(j1, j2) = auxi If j1 <> j2 Then xpox(j2, j1) = xpox(j1, j2 ) Next j2 Next j1 For i1 = 1 To k For j1 = 1 To k For k1 = 1 To k For l1 = 1 To k varb(i1, j1) = varb(i1, j1) + (IXPX (k1, j1) * xpox(k1, l1) * IXPX(l1, i1)) Next l1 Next k1 Next j1 Next i1

Page 55: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

54

aux(1, 1) = Application.TInv(SIG, GL(2)) For i1 = 1 To k R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & " )" R(i1 + 2, 2) = B(i1) R(i1 + 2, 3) = Sqr(varb(i1, i1)) R(i1 + 2, 4) = B(i1) / R(i1 + 2, 3) R(i1 + 2, 5) = Application.TDist(Abs(R(i1 + 2, 4)), GL(2), 2) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0, 0001", R(i1 + 2, 5)) R(i1 + 2, 6) = B(i1) - aux(1, 1) * R(i1 + 2, 3) R(i1 + 2, 7) = B(i1) + aux(1, 1) * R(i1 + 2, 3) Next i1 aux(1, 1) = IIf(k <= 18, 0, IIf(OPT(8, 2) = True, I If(k > 27, 1, 0), 1)) If NPES <> 0 Then tit = " (Variable de Ponderación : " & LVAR(NPES, 1) & ")" Else tit = "" Call M1_ESCRIPTURA(8, "ESTIMACIÓN ROBUSTA (WHITE) " & tit, aux) If k <> 1 Then If OPT(8, 2) Then Call M1_ESCRIPTURA_1(8, varb, B, "MATRIZ DE VARIANZAS y COVARIANZAS (WHITE)") End If End Sub Private Sub M1_09(opcio As Integer) ''''''''''''''''''''' 'HETEROSCEDASTICITAT' ''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''' 'Significat de Heteros() ' 'Heteros(1)= "MQG" o "MV" 'Heteros(2)= 1 a 8 (ponderacions) 9=multiplicativa 'Heteros(3)= Ajustament (True o False) 'Heteros(6)= Altres estimacions ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''' Dim avis(1 To 2) As Boolean, dim1 As Integer, h As Single, iir As Integer, icont As Integer, i2 As Int eger, _ j1 As Integer, lh As Double, lm As Double, sigm a(1 To 8) As String, tit As String, vartot As Doubl e, _ b1() As Double, m1() As Double, b2() As Double, m2() As Double ReDim v(R_XY.Columns.Count - 1 - IIf(IY <> 0, 1, 0) ) As String sigma(1) = "s²(i)=s²(1/Z²)" sigma(2) = "s²(i)=s²(1/Z)" sigma(3) = "s²(i)=s²(1/" & Chr(214) & "Z)" sigma(4) = "s²(i)=s²(1/Ln(Z))" sigma(5) = "s²(i)=s²(Ln(Z))" sigma(6) = "s²(i)=s²(" & Chr(214) & "Z)" sigma(7) = "s²(i)=s²(Z)" sigma(8) = "s²(i)=s²(Z²)" i2 = 0 For j1 = 1 To R_XY.Columns.Count If j1 <> NY And j1 <> IY Then i2 = i2 + 1 v(i2 - 1) = LVAR(j1, 1) End If Next j1 v(i2) = "Ajuste(Xß)" h = Application.min(110, 11 * (UBound(v) + 1)) icont = 0 REITERAR: avis(1) = False avis(2) = False iir = iir + 1 tit = "Modelos de Regresión: Heteroscedasticidad" ERR_LEC = True SORTIR = False Do While ERR_LEC With C2_Varis .Caption = tit & IIf(iir = 1, "", " (Estimació n " & iir & ")") .Frame92.Height = h + 22 .ListBox92.Move Height:=h, Left:=0, Top:=5, Wi dth:=90 .ListBox92.List = v If iir = 5 Then .OtraHeteros9.Enabled = False With .MultiPage1 .Value = 5 .Style = fmTabStyleNone End With

Page 56: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

55

.Show End With If SORTIR Then ERR_LEC = False Loop If SORTIR Then ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F - 2, 1)) SORTIR = False Unload C2_Varis Exit Sub End If If HETEROS(3) Then dim1 = 1 Else dim1 = UBound(VARS ) If HETEROS(1) = "MQG" Then Call M1_09_1(dim1, b1, m 1, vartot) If HETEROS(1) = "MV" Then Call M1_09_2(avis, dim1, b1, m1, b2, m2, lh, lm) ReDim maux(1 To 6), R(1 To k + 2 + IIf(HETEROS(1) = "MV", dim1 + IIf(avis(2) = False, 2, 1), 1), 1 To 5) maux(1) = HETEROS(1) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "err. es." & Chr(10) & "Parámetro" R(1, 4) = "Valor t" R(1, 5) = "Prob |t|" For j1 = 1 To k R(j1 + 2, 1) = "b" & j1 & "(" & LVAR(j1, 2) & " )" R(j1 + 2, 2) = b1(j1) R(j1 + 2, 3) = Sqr(m1(j1, j1)) R(j1 + 2, 4) = R(j1 + 2, 2) / R(j1 + 2, 3) R(j1 + 2, 5) = Application.TDist(Abs(R(j1 + 2, 4)), GL(2), 2) R(j1 + 2, 5) = IIf(R(j1 + 2, 5) < 0.0001, "< 0, 0001", R(j1 + 2, 5)) Next j1 tit = "HETEROSCEDASTICIDAD" If HETEROS(1) = "MQG" Then R(k + 3, 1) = Chr(214) & "ECM = " R(k + 3, 2) = Sqr(m1(k + 1, k + 1) / (N - k)) R(k + 3, 3) = "R" & Chr(178) & " = " & Format(1 - (m1(k + 1, k + 1) / vartot), "0.0000") R(k + 3, 4) = "R" & Chr(178) & " corr = " R(k + 3, 5) = Format(1 - ((m1(k + 1, k + 1) / GL (2)) / (vartot / GL(3))), "0.0000") tit = tit & ". Método MCG: " & sigma(HETEROS(2)) & "; Z=" If HETEROS(3) Then tit = tit & "Ajuste(Xß)" Else If dim1 = 1 Then tit = tit & LVAR(VARS(dim1), 1) Else For j1 = 1 To dim1 tit = tit & IIf(j1 = 1, "", "+") & LVA R(VARS(j1), 1) Next j1 End If End If maux(2) = 34 maux(3) = 40 maux(4) = IIf(HETEROS(2) = 3, 45, IIf(HETEROS(2) = 6, 43, 0)) Else R(k + 3, 1) = "a1" For j1 = 1 To dim1 If HETEROS(3) Then R(k + 2 + j1 + 1, 1) = "a" & j1 + 1 & "Aj uste(Xß)" Else R(k + 2 + j1 + 1, 1) = "a" & j1 + 1 & "(" & LVAR(VARS(j1), 1) & ")" End If Next j1 For j1 = 1 To dim1 + 1 R(k + 2 + j1, 2) = b2(j1) R(k + 2 + j1, 3) = Sqr(m2(j1, j1)) Next j1 If Not avis(2) Then R(k + 2 + dim1 + 2, 1) = "Log L = " R(k + 2 + dim1 + 2, 2) = lh R(k + 2 + dim1 + 2, 4) = "Test: c" & Chr(178) & "(gl=" & dim1 & ") = " R(k + 2 + dim1 + 2, 5) = Format(lm, "#####0.0 00") & "(" & _ Format(Application.C hiDist(lm, dim1), "0.0000") & ")" End If tit = tit & " MULTIPLICATIVA. Método MV: s²(i)=e xp(Za)" maux(2) = 48 maux(3) = 59 If avis(2) Then tit = tit & " ¡¡ Proceso divergente !!" ElseIf Not avis(1) Then tit = tit & " ¡¡ convergencia no alcanzada tras 50 iteraciones !!" End If End If

Page 57: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

56

maux(5) = 0 If (Not HETEROS(5) Or iir = 5) Then maux(5) = 1 icont = icont + 4 + k + IIf(HETEROS(1) = 1, 0, dim1 + 1) If icont >= 75 Then maux(5) = 1 maux(6) = avis(2) Call M1_ESCRIPTURA(9, tit, maux) If HETEROS(5) And iir < 5 Then GoTo REITERAR Unload C2_Varis End Sub Private Sub M1_09_1(nvars, betas, mvc, vartot) ''''''''''''''' 'Estimació MQG' ''''''''''''''' Dim a As Double, aux As Double, i1 As Long, j1 As I nteger, k1 As Integer, sumaux As Double ReDim betas(1 To k), mvc(1 To k + 1, 1 To k + 1) If (HETEROS(2) = 1 Or HETEROS(2) = 8) Then a = IIf( HETEROS(2) = 1, 2, -2) If (HETEROS(2) = 2 Or HETEROS(2) = 7) Then a = IIf( HETEROS(2) = 2, 1, -1) If (HETEROS(2) = 3 Or HETEROS(2) = 6) Then a = IIf( HETEROS(2) = 3, 0.5, -0.5) For i1 = 1 To N aux = 0 If HETEROS(3) Then aux = aux + YHAT(i1) Else For j1 = 1 To nvars aux = aux + R_XY.Rows(i1).Columns(VARS(j 1)) Next j1 End If If HETEROS(2) = 4 Then aux = Log(aux) ElseIf HETEROS(2) = 5 Then aux = 1 / Log(aux) Else aux = aux ^ a End If sumaux = sumaux + aux For j1 = 1 To k + 1 For k1 = j1 To k + 1 mvc(j1, k1) = mvc(j1, k1) + (XY(i1, j1) * aux * XY(i1, k1)) Next k1 Next j1 Next i1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 mvc(k1, j1) = mvc(j1, k1) Next k1 Next j1 vartot = mvc(k + 1, k + 1) Call C_G2SWEEP(1, 0, mvc, N, k + 1, 0.00000001, Fal se) For j1 = 1 To k betas(j1) = mvc(j1, k + 1) For k1 = 1 To k mvc(j1, k1) = mvc(k + 1, k + 1) * mvc(j1, k 1) / (N - k) Next k1 Next j1 End Sub Private Sub M1_09_2(avis, nvars, betas, mvc, betas2 , mvc2, lh, lm) '''''''''''''' 'Estimació MV' '''''''''''''' Dim aux As Double, aux1 As Double, aux2 As Double, crit As Double, i1 As Long, it As Integer, j1 As In teger, _ k1 As Integer, lh0 As Double, lh1 As Double, lh 2 As Double, pi2 As Double ReDim d_b(1 To 2 * (nvars + 1 + k)) As Double, gg(1 To nvars + 1) As Double, _ xy_(1 To Application.max(k + 1, nvars + 2)) A s Double ''''''''''''''''''''''''''''''''''''''''''''''''' 'Estimació inicial de la funció heteroscedàstica' ''''''''''''''''''''''''''''''''''''''''''''''''' ReDim betas(1 To k) As Double, betas2(1 To nvars + 1) As Double, mvc2(1 To nvars + 2, 1 To nvars + 2) As Double For j1 = 1 To k betas(j1) = B(j1) Next j1 For i1 = 1 To N xy_(1) = 1 If HETEROS(3) Then

Page 58: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

57

xy_(2) = YHAT(i1) Else For j1 = 1 To nvars xy_(j1 + 1) = R_XY.Rows(i1).Columns(VARS (j1)) Next j1 End If xy_(nvars + 2) = Log(E(i1) ^ 2) For j1 = 1 To nvars + 2 For k1 = j1 To nvars + 2 mvc2(j1, k1) = mvc2(j1, k1) + (xy_(j1) * xy_(k1)) Next k1 Next j1 Next i1 For j1 = 1 To nvars + 2 For k1 = j1 + 1 To nvars + 2 mvc2(k1, j1) = mvc2(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, 1, mvc2, N, nvars + 2, 0.00000001 , False) For j1 = 1 To nvars + 1 betas2(j1) = mvc2(j1, nvars + 2) Next j1 betas2(1) = betas2(1) + 1.2704 ''''''''' 'Scoring' ''''''''' lh0 = 0 pi2 = Log(2 * Application.pi) For it = 1 To 50 lh = 0 avis(1) = False avis(2) = False ReDim mvc2(1 To nvars + 2, 1 To nvars + 2), mvc (1 To k + 1, 1 To k + 1) For i1 = 1 To N aux2 = 0 For j1 = 1 To k aux2 = aux2 + (XY(i1, j1) * betas(j1)) Next j1 aux2 = XY(i1, k + 1) - aux2 'residu: aux2 aux1 = betas2(1) If HETEROS(3) Then aux1 = aux1 + (YHAT(i1) * betas2(2)) Else For j1 = 1 To nvars aux1 = aux1 + ((R_XY.Rows(i1).Column s(VARS(j1))) * betas2(j1 + 1)) 'pre-ponderació: aux 1' Next j1 End If lh1 = aux1 aux1 = Exp(-aux1) 'ponderació (multipl icativa) lh2 = (aux2 ^ 2) * aux1 lh = lh - 0.5 * (pi2 + lh1 + lh2) 'versemblança For j1 = 1 To k xy_(j1) = XY(i1, j1) Next j1 xy_(k + 1) = aux2 For j1 = 1 To k + 1 For k1 = j1 To k + 1 mvc(j1, k1) = mvc(j1, k1) + (xy_(j1 ) * aux1 * xy_(k1)) 'hessià i gradient d e beta' Next k1 Next j1 aux = aux2 ^ 2 xy_(nvars + 2) = (aux1 * aux) - 1 aux1 = 1 xy_(1) = 1 If HETEROS(3) Then xy_(2) = YHAT(i1) Else For j1 = 1 To nvars xy_(j1 + 1) = R_XY.Rows(i1).Columns( VARS(j1)) Next j1 End If For j1 = 1 To nvars + 2 For k1 = j1 To nvars + 2 mvc2(j1, k1) = mvc2(j1, k1) + (xy_( j1) * aux1 * xy_(k1)) 'hessià i gradient d e alfa' Next k1 Next j1 Next i1

Page 59: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

58

For j1 = 1 To nvars + 2 For k1 = j1 + 1 To nvars + 2 mvc2(k1, j1) = mvc2(j1, k1) Next k1 If j1 < nvars + 2 Then d_b(j1) = mvc2(j1, n vars + 2) Next j1 Call C_G2SWEEP(1, 1, mvc2, N, nvars + 2, 0.0000 0001, False) For j1 = 1 To nvars + 1 betas2(j1) = betas2(j1) + mvc2(j1, nvars + 2) d_b(nvars + 1 + j1) = mvc2(j1, nvars + 2) Next j1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 mvc(k1, j1) = mvc(j1, k1) Next k1 If j1 < k + 1 Then d_b(2 * (nvars + 1) + j1 ) = mvc(j1, k + 1) Next j1 Call C_G2SWEEP(1, 1, mvc, N, k + 1, 0.000000001 , False) For j1 = 1 To k betas(j1) = betas(j1) + mvc(j1, k + 1) d_b(2 * (nvars + 1) + k + j1) = mvc(j1, k + 1) Next j1 crit = Application.max(Abs(lh0 - lh), Applicati on.SumSq(d_b)) 'Criteri de convergèn cia lh0 = lh If crit <= 0.00000001 Then avis(1) = True Exit For End If If crit > 1000000000000# Then avis(2) = True Exit For End If Next it it = it - 1 For j1 = 1 To nvars + 1 For k1 = 1 To nvars + 1 mvc2(j1, k1) = 2 * mvc2(j1, k1) 'Correcció matriu var iàncies i covariàncies Next k1 Next j1 ReDim Preserve betas(1 To k + nvars + 1) For j1 = k + 1 To k + nvars + 1 betas(j1) = betas2(j1 - k) Next j1 '''''''''''''''''''''''''''' 'Test d'heteroscedasticitat' '''''''''''''''''''''''''''' If Not avis(2) Then ReDim m(1 To nvars + 2, 1 To nvars + 2) As Doubl e For i1 = 1 To N xy_(1) = 1 If HETEROS(3) Then xy_(2) = YHAT(i1) Else For j1 = 1 To nvars xy_(j1 + 1) = R_XY.Rows(i1).Columns(V ARS(j1)) Next j1 End If aux = (E(i1) ^ 2) / (Sq(2) / N) For j1 = 1 To nvars + 1 gg(j1) = gg(j1) + (xy_(j1) * (aux - 1)) For k1 = j1 To nvars + 1 m(j1, k1) = m(j1, k1) + (xy_(j1) * ( aux) * xy_(k1)) Next k1 Next j1 Next i1 For j1 = 1 To nvars + 1 For k1 = j1 + 1 To nvars + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, 1, m, N, nvars + 2, 0.00000000 1, False) lm = 0 For j1 = 1 To nvars + 1 For k1 = 1 To nvars + 1 lm = lm + (gg(j1) * m(j1, k1) * gg(k1))

Page 60: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

59

Next k1 Next j1 lm = 0.5 * lm End If End Sub Private Sub M1_10(opcio As Integer) '''''''''''''''' 'AUTOCORRELACIO' '''''''''''''''' ''''''''''''''''''''''''''''''''''''''' 'Significat de AUTO() ' 'AUTO(1)= ordre autorregressiu 1 a 12 'AUTO(2)= mètode estimació 1=YW, 2=IYW 'AUTO(3)= convergencia 'AUTO(4)= iteraciones 'AUTO(5)= Nueva estimación '''''''''''''''''''''''''''''''''''''' Dim aux(1), avis(1 To 2) As Boolean, betas() As Dou ble, det As Double, icont As Integer, _ iir As Integer, it As Integer, i1 As Integer, m () As Double, matrix() As Double, _ m1() As Double, stats() As Double, tit As Strin g, v(11) As Integer, _ vconv(5) As String, viter(49) As Integer For i1 = 12 To 1 Step -1 v(12 - i1) = i1 Next i1 For i1 = 1 To 6 vconv(i1 - 1) = "1E-0" & i1 Next i1 For i1 = 50 To 1 Step -1 viter(50 - i1) = i1 Next i1 icont = 0 REITERAR: avis(1) = False avis(2) = False iir = iir + 1 tit = "Modelos de Regresión: Autocorrelación" With C2_Varis .Aceptar.Top = 120 .Cancelar.Top = 120 .Caption = tit & IIf(iir <> 1, " (núm. " & iir & ")", "") With .ListBox10 .Move Height:=12 .List = v .Selected(11) = True End With With .ListBox1021 .Move Height:=12 .List = vconv .Selected(2) = True End With If iir = 5 Then .OtraAuto10.Enabled = False .OtraAuto10.Value = False With .ListBox1022 .Move Height:=12 .List = viter .Selected(25) = True End With With .MultiPage1 .Height = 115 .Style = fmTabStyleNone .Value = 6 End With .Height = 165 .Show End With If SORTIR Then ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F - 2, 1)) SORTIR = False Unload C2_Varis Exit Sub End If ReDim betas(1 To k + AUTO(1)) As Double

Page 61: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

60

Call M1_10_1(avis, E, betas, matrix, m1, Sq(2), det ) If avis(1) Then Exit Sub Call M1_10_2(avis, betas, matrix, m, m1, det, it, s tats) ReDim R(1 To k + AUTO(1) + IIf(AUTO(2) = 1, 7, 8), 1 To 5) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "err. es." & Chr(10) & "Parámetro" R(1, 4) = "Valor t" R(1, 5) = "Prob |t|" For i1 = 1 To k R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & " )" R(i1 + 2, 2) = betas(i1) R(i1 + 2, 3) = Sqr(m(i1, i1)) R(i1 + 2, 4) = betas(i1) / R(i1 + 2, 3) R(i1 + 2, 5) = Application.TDist(Abs(R(i1 + 2, 4)), GL(2) - AUTO(1), 2) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0, 0001", R(i1 + 2, 5)) Next i1 For i1 = 1 To AUTO(1) R(k + i1 + 2, 1) = " AR(" & i1 & ")" R(k + i1 + 2, 2) = betas(k + i1) R(k + i1 + 2, 3) = Sqr(m1(i1, i1)) R(k + i1 + 2, 4) = betas(k + i1) / R(k + i1 + 2 , 3) R(k + i1 + 2, 5) = Application.TDist(Abs(R(k + i1 + 2, 4)), GL(2) - AUTO(1), 2) R(k + i1 + 2, 5) = IIf(R(k + i1 + 2, 5) < 0.000 1, "< 0,0001", R(k + i1 + 2, 5)) Next i1 R(k + AUTO(1) + 3, 1) = " SCE" R(k + AUTO(1) + 3, 2) = m(k + 1, k + 1) R(k + AUTO(1) + 4, 1) = " ECM" R(k + AUTO(1) + 4, 2) = m(k + 1, k + 1) / (GL(2) - AUTO(1)) R(k + AUTO(1) + 5, 1) = Chr(214) & "ECM" R(k + AUTO(1) + 5, 2) = Sqr(m(k + 1, k + 1) / (GL(2 ) - AUTO(1))) R(k + AUTO(1) + 6, 1) = " R" & Chr(178) & " Total" R(k + AUTO(1) + 6, 2) = stats(1) R(k + AUTO(1) + 7, 1) = " gl" R(k + AUTO(1) + 7, 2) = N - k - AUTO(1) If AUTO(2) <> 1 Then R(k + AUTO(1) + 8, 1) = " Iter aciones" If AUTO(2) <> 1 Then R(k + AUTO(1) + 8, 2) = it R(k + AUTO(1) + 3, 4) = " Log L" R(k + AUTO(1) + 3, 5) = stats(2) R(k + AUTO(1) + 4, 4) = "Crit. Akaike" R(k + AUTO(1) + 4, 5) = stats(3) R(k + AUTO(1) + 5, 4) = "Crit. Schwartz" R(k + AUTO(1) + 5, 5) = stats(4) R(k + AUTO(1) + 6, 4) = "DW" R(k + AUTO(1) + 6, 5) = stats(5) R(k + AUTO(1) + 7, 4) = "Obs." R(k + AUTO(1) + 7, 5) = N tit = "AUTOCORRELACIÓN. Método: " If AUTO(1) = 1 Then tit = tit & "Prais-Winsten" If AUTO(1) > 1 Then tit = tit & "Yule-Walker" If AUTO(2) = 2 Then tit = tit & " iterativo" & IIf( avis(2), "(estimación no convergente)", "") icont = icont + 3 + k + AUTO(1) + IIf(AUTO(2) = 1, 5, 6) If Not AUTO(5) Or iir = 5 Then aux(1) = 1 If icont >= 75 Then aux(1) = 1 Call M1_ESCRIPTURA(10, tit, aux) If AUTO(5) And iir < 5 Then GoTo REITERAR Unload C2_Varis End Sub Private Sub M1_10_1(avis, e_, betas, matrix, m1, e_ 2, det) Dim aux As Double, i1 As Integer, j1 As Integer, k1 As Integer, kk As Integer, maux() As Double kk = AUTO(1) ReDim m1(1 To kk + 1, 1 To kk + 1), rho(1 To kk) As Double ''''''''''''''''''''''' 'EQUACIONS YULE-WALKER' ''''''''''''''''''''''' ReDim maux(1 To kk + 1, 1 To kk + 1) For i1 = 1 To kk rho(i1) = 0 For j1 = i1 + 1 To N rho(i1) = rho(i1) + (e_(j1) * e_(j1 - i1)) Next j1 rho(i1) = rho(i1) / e_2 Next i1 For i1 = 1 To kk For j1 = i1 + 1 To kk

Page 62: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

61

maux(i1, j1) = rho(j1 - i1) Next j1 maux(i1, i1) = 1 maux(i1, kk + 1) = rho(i1) For j1 = 1 To kk + 1 maux(j1, i1) = maux(i1, j1) Next j1 maux(kk + 1, kk + 1) = 1 Next i1 Call C_G2SWEEP(1, 0, maux, N - kk, kk + 1, 0.000000 001, False) aux = 0 For i1 = 1 To kk betas(k + i1) = maux(i1, kk + 1) aux = aux + (betas(k + i1) * rho(i1)) For j1 = 1 To kk m1(i1, j1) = (maux(kk + 1, kk + 1) / (N - k - kk)) * maux(i1, j1) Next j1 Next i1 ReDim maux(1 To kk + 2, 1 To kk + 2) For i1 = 1 To kk For j1 = i1 + 1 To kk + 1 maux(i1, j1) = rho(j1 - i1) Next j1 maux(i1, i1) = 1 For j1 = 1 To kk + 1 maux(j1, i1) = maux(i1, j1) Next j1 maux(kk + 1, kk + 1) = 1 Next i1 For i1 = 1 To kk + 1 For j1 = 1 To kk + 1 maux(i1, j1) = maux(i1, j1) / (1 - aux) Next j1 Next i1 Call C_G2SWEEP(1, 0, maux, N - kk, kk + 2, 0.000000 001, False) ''''''''''''''''''''''''''' 'Descomposició de Cholesky' ''''''''''''''''''''''''''' Dim d1 As Double, d2 As Integer, X As Double ReDim p(1 To kk + 1) As Double d1 = 1 d2 = 0 For i1 = 1 To kk + 1 For j1 = i1 To kk + 1 X = maux(i1, j1) For k1 = i1 - 1 To 1 Step -1 X = X - maux(j1, k1) * maux(i1, k1) Next k1 If j1 = i1 Then d1 = d1 * X If X = 0 Then d2 = 0 MsgBox "El proceso no es estacionario .", vbCritical, TITOL avis(1) = True Exit Sub End If l1: If Abs(d1) >= 1 Then d1 = d1 * 0.0625 d2 = d2 + 4 GoTo l1 End If l2: If Abs(d1) < 0.0625 Then d1 = d1 * 16 d2 = d2 - 4 GoTo l2 End If If X < 0 Then MsgBox "El proceso no es estacionario .", vbCritical, TITOL avis(1) = True Exit Sub End If p(i1) = 1 / Sqr(X) Else maux(j1, i1) = X * p(i1) End If Next j1 Next i1 det = d1 * 2 ^ d2 ReDim matrix(1 To kk, 1 To kk) For i1 = 2 To kk + 1

Page 63: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

62

For j1 = 2 To kk + 1 matrix(i1 - 1, j1 - 1) = maux(i1, j1) Next j1 Next i1 ReDim maux(1 To kk, 1 To kk) For i1 = 1 To kk For j1 = 1 To kk If i1 > j1 Then maux(i1, j1) = matrix(i1, j 1) If i1 = j1 Then maux(i1, j1) = 1 / p(kk + 2 - i1) If i1 < j1 Then maux(i1, j1) = 0 Next j1 Next i1 ReDim matrix(1 To kk, 1 To kk) For i1 = 1 To kk For j1 = 1 To kk matrix(i1, j1) = maux(i1, j1) Next j1 Next i1 For k1 = 1 To kk If k1 <= 4 Then j1 = 1 Else j1 = Abs(Int(-k1 / 2)) - 1 Next k1 For k1 = 1 To j1 For i1 = k1 + 1 To kk - k1 matrix(i1, k1) = maux(kk - (k1 - 1), kk - i 1 + 1) matrix(kk - (k1 - 1), kk - i1 + 1) = maux(i 1, k1) Next i1 Next k1 End Sub Private Sub M1_10_2(avis, betas, matrix, m, m1, det , it, stats) '''''''''''''''''''''''''' 'ESTIMACIÓ AUTOCORRELACIÓ' '''''''''''''''''''''''''' Dim ar As Integer, aux As Double, e_2 As Double, i1 As Integer, j1 As Integer, k1 As Integer ar = AUTO(1) ReDim d1(1 To ar) As Double, d2(1 To ar) As Double, e_(1 To N) As Double, e_star(1 To N) As Double, _ xy_(1 To k + 1) As Double For it = 0 To AUTO(4) ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''' 'Estimació de ß utilitzant les 'p' primeres obs ervacions' ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''' ReDim m(1 To k + 1, 1 To k + 1), stats(1 To 5) For i1 = 1 To N If i1 <= ar Then For j1 = 1 To k + 1 xy_(j1) = 0 For k1 = 1 To i1 xy_(j1) = xy_(j1) + (matrix(i1, k1) * XY(k1, j1)) Next k1 Next j1 Else For j1 = 1 To k + 1 xy_(j1) = 0 For k1 = 1 To ar xy_(j1) = xy_(j1) + (betas(k + k 1) * XY(i1 - k1, j1)) Next k1 xy_(j1) = XY(i1, j1) - xy_(j1) Next j1 End If For j1 = 1 To k + 1 For k1 = j1 To k + 1 m(j1, k1) = m(j1, k1) + (xy_(j1) * xy_(k1)) Next k1 Next j1 Next i1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, 0, m, N, k + 1, 0.000000001, False) For i1 = 1 To k betas(i1) = m(i1, k + 1) For j1 = 1 To k m(i1, j1) = (m(k + 1, k + 1) / (N - k - ar)) * m(i1, j1) Next j1 Next i1

Page 64: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

63

e_2 = 0 For i1 = 1 To N aux = 0 For j1 = 1 To k aux = aux + (betas(j1) * XY(i1, j1)) Next j1 e_(i1) = XY(i1, k + 1) - aux e_2 = e_2 + (e_(i1) ^ 2) Next i1 ''''''''''''''''''''''''' 'Criteri de convergència' ''''''''''''''''''''''''' For i1 = 1 To ar d1(i1) = Abs(d2(i1) - betas(k + i1)) d2(i1) = betas(k + i1) Next i1 If AUTO(2) <> 1 Then avis(2) = True If Application.max(d1) <= AUTO(3) Then avis(2) = False Exit For Else Call M1_10_1(avis, e_, betas, matrix, m1, e_2, det) If avis(1) Then Exit Sub End If End If Next it '''''''''''''''''''''''''''''''''''''''''''' 'Càlcul R2, R2c, versemblança, AIC, SBC, DW' '''''''''''''''''''''''''''''''''''''''''''' e_2 = 0 For i1 = 1 To N If i1 <= ar Then For k1 = 1 To ar e_star(i1) = e_star(i1) + (matrix(i1, k1 ) * e_(k1)) Next k1 Else aux = 0 For k1 = 1 To ar aux = aux + (betas(k + k1) * e_(i1 - k1) ) Next k1 e_star(i1) = e_(i1) - aux End If e_2 = e_2 + (e_star(i1) ^ 2) If i1 > 1 Then stats(5) = stats(5) + (e_star(i1 ) - e_star(i1 - 1)) ^ 2 Next i1 stats(1) = 1 - (e_2 / (Sq(3))) stats(2) = -(N / 2) * ((Log(2 * Application.pi)) + Log(m(k + 1, k + 1) / N) + 1) + 0.5 * Log(det) stats(3) = -2 * stats(2) + 2 * (k + ar) stats(4) = -2 * stats(2) + (k + ar) * Log(N) stats(5) = stats(5) / e_2 End Sub Private Sub M1_11(opcio As Integer) ''''''''''''''''''''''''' 'VARIABLES INSTRUMENTALS' ''''''''''''''''''''''''' Dim h As Single, i1 As Integer, j1 As Integer, k1 A s Integer ReDim v(NX - 1) As String For i1 = 1 To NX v(i1 - 1) = LVAR(VX(i1), 1) Next i1 h = Application.min(70, 11 * (UBound(v) + 2)) With C2_Varis .Aceptar11.Top = h + 25 .Cancelar11.Top = h + 25 .Caption = "Modelos de Regresión: Estimación por variables instrumentales" .Frame111.Visible = True .Frame111.Height = h + 55 .ListBox111.Height = h .ListBox111.List = v With .MultiPage1 .Height = h + 75 .Value = 7

Page 65: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

64

.Style = fmTabStyleNone End With .Height = h + 95 End With ERR_LEC = True SORTIR = False Do While ERR_LEC C2_Varis.Show If SORTIR Then ERR_LEC = False Loop Unload C2_Varis If SORTIR Then SORTIR = False Exit Sub End If Dim error_inversio(1 To 2), s2vi As Double, vis() A s Integer, sargan As Double, tit As String ReDim bvi(1 To k) As Double, exog(1 To UBound(VI_X) ) As Double, varbvi(1 To k, 1 To k) As Double error_inversio(1) = False Call M1_11_1(error_inversio, vis, bvi, s2vi, varbvi , exog, sargan) If error_inversio(1) Then MsgBox error_inversio(2), vbCritical, TITOL & "( Variables instrumentales)" SORTIR = False ERR_LEC = False Unload C2_Varis Exit Sub End If If k <= 18 Then OPT(11, 2) = True If k > 18 Then OPT(0, 0) = 6 With C2_Varis .Aceptar.Top = 45 .Cancelar.Top = 45 .Caption = "Modelos de Regresión: Estimación p or variables instrumentales (M2CE)" .c01.Caption = "Estimación de los parámetros" .c01.Locked = True .c02.Caption = "Matriz de varianzas y covarian zas (M2CE)" .c02.Value = False .c03.Visible = False .c04.Visible = False .c05.Visible = False .Frame0.Height = 35 With .MultiPage1 .Height = 45 .Style = fmTabStyleNone .Value = 0 End With .Height = 90 .Show End With If SORTIR Then SORTIR = False Unload C2_Varis End If Call M1_02(11, s2vi) Dim instrums As Integer For i1 = 1 To UBound(VI_X) instrums = instrums + vis(i1) Next i1 ReDim R(1 To k + 4 + UBound(VI_X) + IIf(instrums > UBound(VI_X), 2, 0), 1 To 7), aux(1 To 1, 1 To 1) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "err. es." & Chr(10) & "Parámetro" R(1, 4) = "Valor t" R(1, 5) = "Prob |t|" R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" aux(1, 1) = Application.TInv(SIG, GL(2)) For i1 = 1 To k R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & " )" R(i1 + 2, 2) = bvi(i1) R(i1 + 2, 3) = Sqr(varbvi(i1, i1)) R(i1 + 2, 4) = bvi(i1) / R(i1 + 2, 3)

Page 66: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

65

R(i1 + 2, 5) = Application.TDist(Abs(R(i1 + 2, 4)), GL(2), 2) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0, 0001", R(i1 + 2, 5)) R(i1 + 2, 6) = bvi(i1) - aux(1, 1) * R(i1 + 2, 3) R(i1 + 2, 7) = bvi(i1) + aux(1, 1) * R(i1 + 2, 3) Next i1 R(k + 3, 1) = "Variable" & Chr(10) & "instrumentada " R(k + 3, 2) = "Test de Wu-Hausman (HO: exogeneidad) " R(k + 3, 5) = "Instrumentos" R(k + 4, 2) = "Valor t" R(k + 4, 3) = "gl" R(k + 4, 4) = "Prob |t|" For i1 = 1 To UBound(VI_X) R(k + 4 + i1, 1) = LVAR(VI_X(i1), 2) k1 = 0 tit = "" For j1 = 1 To UBound(VI_Z, 1) If VI_Z(j1, i1) <> "" Then k1 = k1 + 1 tit = tit & LVAR(VI_Z(j1, i1), 1) & IIf( k1 < vis(i1), ", ", "") End If Next j1 R(k + 4 + i1, 2) = exog(i1) R(k + 4 + i1, 3) = N - instrums - 1 R(k + 4 + i1, 4) = Application.TDist(Abs(R(k + 4 + i1, 2)), N - instrums - 1, 2) R(k + 4 + i1, 4) = IIf(R(k + 4 + i1, 4) < 0.000 1, "< 0,0001", R(k + 4 + i1, 4)) R(k + 4 + i1, 5) = tit Next i1 If instrums > UBound(VI_X) Then R(k + 5 + UBound(VI_X), 5) = "Valor c²" R(k + 5 + UBound(VI_X), 6) = "gl" R(k + 5 + UBound(VI_X), 7) = "Prob > c²" R(k + 6 + UBound(VI_X), 3) = "Test de Sargan (HO : validez de instrumentos)" R(k + 6 + UBound(VI_X), 5) = sargan R(k + 6 + UBound(VI_X), 6) = instrums - UBound(V I_X) R(k + 6 + UBound(VI_X), 7) = Application.ChiDist (sargan, instrums - UBound(VI_X)) R(k + 6 + UBound(VI_X), 7) = IIf(R(k + 6 + UBoun d(VI_X), 7) < 0.0001, "< 0,0001", R(k + 6 + UBound( VI_X), 7)) End If aux(1, 1) = IIf(k <= 18, 0, IIf(OPT(11, 2) = True, IIf(k > 27, 1, 0), 1)) If NPES <> 0 Then tit = " (Variable de Ponderación : " & LVAR(NPES, 1) & ")" Else tit = "" Call M1_ESCRIPTURA(11, "ESTIMACIÓN POR VARIABLES IN STRUMENTALES (MC2E) " & tit, aux) If k <> 1 Then If OPT(11, 2) Then Call M1_ESCRIPTURA_1(11, varb vi, B, "MATRIZ DE VARIANZAS y COVARIANZAS (MC2E)") End If End Sub Private Sub M1_11_1(error_inversio, vis, bvi, s2vi, varbvi, exog, sargan) ''''''''''''''''''''''''''''' 'Estimació del model per MQ2E ''''''''''''''''''''''''''''' Dim aux As Double, auxn() As Double, auxp() As Doub le, dimaux As Integer, indx() As Integer, _ i2 As Long, i1 As Integer, j1 As Integer, k1 As Integer, l1 As Integer ReDim evi(1 To N) As Double, zy(1 To N, 1 To k + 1) As Double, vi_hat(1 To N, 1 To UBound(VI_X)) As Do uble, _ vis(1 To UBound(VI_X)), xpz(1 To k + 1, 1 To k + 1) As Double, zpx(1 To k + 1, 1 To k + 1) As Do uble, _ zpz(1 To k + 1, 1 To k + 1) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''' 'Determina quans instruments s'han seleccionat per a cada variable a "instrumentar" ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''' For i1 = 1 To UBound(VI_X) vis(i1) = 0 For j1 = 1 To UBound(VI_Z, 1) If VI_Z(j1, i1) <> "" Then vis(i1) = vis(i1 ) + 1 Next j1 Next i1 'Call m1_11_aux(1, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, exog, sargan) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''' 'Col·loca a VI_X la columna de XY de les "instrumen tades" (abans hi havia els noms) 'Col·loca a VI_Z la columna de R_XY dels instrument s (abans hi havia els noms) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''' For i1 = 1 To UBound(VI_X) For j1 = 1 To k If LVAR(j1, 2) = VI_X(i1) Then VI_X(i1) = j 1

Page 67: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

66

Next j1 For j1 = 1 To R_XY.Columns.Count For k1 = 1 To UBound(VI_Z, 1) If LVAR(j1, 1) = VI_Z(k1, i1) Then VI_Z (k1, i1) = j1 Next k1 Next j1 Next i1 'Call m1_11_aux(2, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, exog, sargan) For i1 = 1 To UBound(VI_X) dimaux = k + vis(i1) ReDim auxn(1 To N, 1 To dimaux) As Double, auxp (1 To dimaux, 1 To dimaux) As Double, indx(1 To dim aux - 1) As Integer l1 = 0 If IC = 1 Then l1 = l1 + 1 indx(l1) = 1 End If For j1 = IC + 1 To k If VI_X(i1) <> j1 Then l1 = l1 + 1 indx(l1) = j1 'Posició a XY de les "instrumentades" End If Next j1 l1 = 0 For j1 = 1 To UBound(VI_Z, 1) If VI_Z(j1, i1) <> "" Then l1 = l1 + 1 indx(k - 1 + l1) = VI_Z(j1, i1) 'Posició a R_XY dels instruments End If Next j1 For i2 = 1 To N For j1 = 1 To k - 1 auxn(i2, j1) = XY(i2, indx(j1)) 'Omple Z auxiliar(1a. etapa) amb les exò genes Next j1 For j1 = k To dimaux - 1 auxn(i2, j1) = R_XY.Rows(i2).Columns(in dx(j1)) 'Omple Z auxiliar(1a. etapa) amb els ins truments Next j1 auxn(i2, dimaux) = XY(i2, VI_X(i1)) 'Omple Z auxiliar(1a. etapa) amb la "instrumentada" For j1 = 1 To dimaux For k1 = 1 To dimaux auxp(j1, k1) = auxp(j1, k1) + (auxn (i2, j1) * auxn(i2, k1) * PES(i2)) Next k1 Next j1 Next i2 Call C_G2SWEEP(0, IC, auxp, N, dimaux, 0.000000 01, error_inversio(1)) If error_inversio(1) Then error_inversio(2) = "Error en la estimación de la 1a. etapa de MQ2E para " & LVAR(VX(i1), 2) & "." Exit Sub End If ' If UBound(VI_X) = 1 And UBound(VI_Z, 1) > 1 Th en _ ' Call m1_11_aux(30 + i1, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, hausman , sargan) For i2 = 1 To N vi_hat(i2, i1) = 0 For j1 = 1 To dimaux - 1 vi_hat(i2, i1) = vi_hat(i2, i1) + auxn( i2, j1) * auxp(j1, dimaux) 'instrument estimat a MQ 2E (1a. etapa) Next j1 Next i2 Next i1 For i2 = 1 To N For j1 = 1 To k zy(i2, j1) = XY(i2, j1) 'Omple Z amb les exogenes no "instrument ades" Next j1 For j1 = 1 To UBound(VI_X) zy(i2, VI_X(j1)) = vi_hat(i2, j1) 'Omple Z amb l'instrument estimat de cad a "instrumentada" Next j1 zy(i2, k + 1) = XY(i2, k + 1) 'Omple Z amb l'endògena del model origin al Next i2 'Call m1_11_aux(4, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, exog, sargan)

Page 68: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

67

For i2 = 1 To N For j1 = 1 To k + 1 For k1 = 1 To k + 1 zpx(j1, k1) = zpx(j1, k1) + (zy(i2, j1) * XY(i2, k1) * PES(i2)) xpz(j1, k1) = xpz(j1, k1) + (XY(i2, j1) * zy(i2, k1) * PES(i2)) zpz(j1, k1) = zpz(j1, k1) + (zy(i2, j1) * zy(i2, k1) * PES(i2)) Next k1 Next j1 Next i2 'Call m1_11_aux(5, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, exog, sargan) Call C_G2SWEEP(0, IC, zpx, N, k + 1, 0.00000001, er ror_inversio(1)) If error_inversio(1) Then error_inversio(2) = "Z'X, construida a partir de los instrumentos seleccionados, no es semidefinida positiva." Exit Sub End If Call C_G2SWEEP(0, IC, xpz, N, k + 1, 0.00000001, Fa lse) 'Call m1_11_aux(6, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, exog, sargan) For j1 = 1 To k bvi(j1) = zpx(j1, k + 1) Next j1 For i2 = 1 To N aux = 0 For j1 = 1 To k aux = aux + (XY(i2, j1) * bvi(j1) * PES(i2) ) 'ajustaments Next j1 evi(i2) = XY(i2, k + 1) - aux s2vi = s2vi + evi(i2) ^ 2 'estimador de sigma a partir de la suma de quadrats dels residus Next i2 s2vi = s2vi / (N - k) For i1 = 1 To k For j1 = 1 To k For k1 = 1 To k For l1 = 1 To k varbvi(i1, j1) = varbvi(i1, j1) + ( zpx(i1, k1) * zpz(k1, l1) * xpz(l1, j1)) Next l1 Next k1 Next j1 Next i1 For i1 = 1 To k For j1 = 1 To k varbvi(i1, j1) = s2vi * varbvi(i1, j1) Next j1 Next i1 Call M1_11_2(vis, evi, s2vi, exog, sargan) 'Te sts de Hausman y Sargan 'Call m1_11_aux(7, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, s2vi, varbvi, exog, sargan) End Sub Private Sub M1_11_2(vis, evi, s2vi, exog, sargan) Dim dimwy As Integer, i1 As Integer, i2 As Long, j1 As Integer, k1 As Integer For i1 = 1 To UBound(VI_X) dimwy = dimwy + vis(i1) Next i1 dimwy = dimwy + IC + 1 ReDim indx(1 To dimwy - IC - 1) As Integer, wy(1 To N, 1 To dimwy) As Double k1 = 0 For i1 = 1 To UBound(VI_X) For j1 = 1 To UBound(VI_Z, 1) If VI_Z(j1, i1) <> "" Then k1 = k1 + 1 indx(k1) = VI_Z(j1, i1) 'posició a R_XY de tots els instrument s utilitzats End If Next j1 Next i1 For i2 = 1 To N

Page 69: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

68

If IC = 1 Then wy(i2, 1) = 1 'omple la 1a. columna si hi a terme in dependent For i1 = 1 To dimwy - IC - 1 wy(i2, i1 + IC) = R_XY.Rows(i2).Columns(ind x(i1)) 'omple amb els instruments Next i1 Next i2 ''''''''''''''''''''''''''''''''''''' 'Test de Sargan: validesa instruments ''''''''''''''''''''''''''''''''''''' ReDim wpw(1 To dimwy, 1 To dimwy) For i2 = 1 To N wy(i2, dimwy) = evi(i2) 'omple amb els residus de VI For i1 = 1 To dimwy For j1 = 1 To dimwy wpw(i1, j1) = wpw(i1, j1) + (wy(i2, i1) * wy(i2, j1) * PES(i2)) Next j1 Next i1 Next i2 Call C_G2SWEEP(0, IC, wpw, N, dimwy, 0.00000001, Fa lse) sargan = (N - k) * (1 - (wpw(dimwy, dimwy) / ((N - k) * s2vi))) '''''''''''''''''''''''''''''''''''''''''''''''' 'Test de Wu-Hausman: exogeneïtat dels regressors '''''''''''''''''''''''''''''''''''''''''''''''' Dim res As Double For i1 = 1 To UBound(VI_X) ReDim wpw(1 To dimwy, 1 To dimwy), auxn(1 To k + 2) As Double, auxp(1 To k + 2, 1 To k + 2) As Dou ble For i2 = 1 To N wy(i2, dimwy) = XY(i2, VI_X(i1)) 'omple amb la variable "instrumentada" For j1 = 1 To dimwy For k1 = 1 To dimwy wpw(j1, k1) = wpw(j1, k1) + (wy(i2, j1) * wy(i2, k1) * PES(i2)) Next k1 Next j1 Next i2 Call C_G2SWEEP(0, IC, wpw, N, dimwy, 0.00000001 , False) For i2 = 1 To N res = 0 For j1 = 1 To dimwy - 1 res = res + (wy(i2, dimwy) - (wy(i2, j1 ) * wpw(j1, dimwy))) Next j1 For j1 = 1 To k auxn(j1) = XY(i2, j1) Next j1 auxn(k + 1) = res auxn(k + 2) = XY(i2, k + 1) For j1 = 1 To k + 2 For k1 = 1 To k + 2 auxp(j1, k1) = auxp(j1, k1) + (auxn (j1) * auxn(k1) * PES(i2)) Next k1 Next j1 Next i2 Call C_G2SWEEP(0, IC, auxp, N, k + 2, 0.0000000 1, False) exog(i1) = auxp(i1 + 1, k + 2) / Sqr(auxp(k + 2 , k + 2) * auxp(i1 + 1, i1 + 1) / (N - k)) Next i1 End Sub Private Sub m1_11_aux(opcio As Integer, indx, vis, auxn, auxp, zy, zpx, xpz, zpz, bvi, evi, svi, varbv i, exog, sargan) Dim i1 As Integer, j1 As Integer If opcio = 1 Then 'les variables són noms Debug.Print "VI_X", "vis" For i1 = 1 To UBound(VI_X) Debug.Print VI_X(i1), vis(i1) Next i1 For j1 = 1 To UBound(VI_X) Debug.Print "VI_Z(," & j1 & ")" For i1 = 1 To UBound(VI_Z, 1) Debug.Print VI_Z(i1, j1) Next i1 Next j1 ElseIf opcio = 2 Then 'les variables són la posició a XY(exògenes) i R_XY(instruments) Debug.Print "VI_X", "vis" For i1 = 1 To UBound(VI_X) Debug.Print VI_X(i1), vis(i1) Next i1

Page 70: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

69

For j1 = 1 To UBound(VI_X) Debug.Print "VI_Z(," & j1 & ")" For i1 = 1 To UBound(VI_Z, 1) Debug.Print VI_Z(i1, j1) Next i1 Next j1 ElseIf opcio > 30 Then 'indx indica l a posició a XY(exògenes) i R_XY(instruments) de la matriu de la 1a. etapa Debug.Print "indx" & opcio - 30 For i1 = 1 To UBound(indx) Debug.Print indx(i1) Next i1 Debug.Print "auxn" & opcio - 30 For i1 = 1 To N Debug.Print Format(auxn(i1, 1), "#0"), Forma t(auxn(i1, 2), "#0.000000"), Format(auxn(i1, 3), "#0.000000"), Format(auxn(i1, 4), "#0.000000"), For mat(auxn(i1, 5), "#0.000000") Next i1 Debug.Print "auxp" & opcio - 30 For i1 = 1 To UBound(auxp) Debug.Print Format(auxp(i1, 1), "#0.000000") , Format(auxp(i1, 2), "#0.000000"), Format(auxp(i1, 3), "#0.000000"), Format(auxp(i1, 4), "#0.000000"), For mat(auxp(i1, 5), "#0.000000") Next i1 ElseIf opcio = 4 Then Debug.Print "X Y" For i1 = 1 To N Debug.Print Format(XY(i1, 1), "#0"), Format( XY(i1, 2), "#0.000000"), Format(XY(i1, 3), "#0.0000 00"), Format(XY(i1, 4), "#0.000000") Next i1 Debug.Print "Z Y" For i1 = 1 To N Debug.Print Format(zy(i1, 1), "#0"), Format( zy(i1, 2), "#0.000000"), Format(zy(i1, 3), "#0.0000 00"), Format(zy(i1, 4), "#0.000000") Next i1 ElseIf opcio = 5 Or opcio = 6 Then Debug.Print IIf(opcio = 5, "Z'X", "(Z'X)¹") For i1 = 1 To k + 1 Debug.Print Format(zpx(i1, 1), "###0.0000"), Format(zpx(i1, 2), "###0.0000"), Format(zpx(i1, 3) , "###0.0000"), Format(zpx(i1, 4), "###0.0000") Next i1 Debug.Print IIf(opcio = 5, "X'Z", "(X'Z)¹") For i1 = 1 To k + 1 Debug.Print Format(xpz(i1, 1), "###0.0000"), Format(xpz(i1, 2), "###0.0000"), Format(xpz(i1, 3) , "###0.0000"), Format(xpz(i1, 4), "###0.0000") Next i1 Else Debug.Print "ß-VI" For i1 = 1 To k Debug.Print Format(bvi(i1), "###0.0000") Next i1 Debug.Print "sigma-VI" Debug.Print Format(svi, "###0.0000") Debug.Print "VAR-VI" For i1 = 1 To k Debug.Print Format(varbvi(i1, 1), "###0.0000 "), Format(varbvi(i1, 2), "###0.0000"), Format(varb vi(i1, 3), "###0.0000") ', Format(varbvi(i1, 4), "###0.000 0") Next i1 Debug.Print "Test de exogeneïtat" For i1 = 1 To UBound(VI_X) Debug.Print exog(i1) Next i1 Debug.Print "Test de Sargan" Debug.Print sargan End If End Sub Private Sub M1_12(opcio As Integer) ''''''''''' 'BOOTSTRAP' ''''''''''' Dim avis As String, i1 As Integer, i2 As Integer, j 1 As Integer, j2 As Integer ReDim a(1 To N) As Integer

Page 71: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

70

avis = " En el caso de que N sea elevado, se recomi enda utilizar el método" & Chr(10) & _ " de 'remuestreo por residuos', ya que el mé todo 'pareado' requiere" & Chr(10) & _ " muchos más recursos de cálculo." & Chr(10) & Chr(10) & _ " Ambos métodos utilizan 1.000 extracciones aleatorias de idéntico" & Chr(10) & _ " tamaño N que la muestra original." With C2_Varis .Aceptar.Top = 150 .Cancelar.Top = 150 .Caption = "Modelos de Regresión: Estimación 'boo tstrap'" .Label12.Caption = avis With .MultiPage1 .Height = 145 .Style = fmTabStyleNone .Value = 8 End With .Height = 195 .Show End With If SORTIR Then ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F - 2, 1)) SORTIR = False Unload C2_Varis Exit Sub End If ''''''''''''''''''''''''''''' 'Guarda la matriu XY original ''''''''''''''''''''''''''''' ReDim xya(1 To N, 1 To k + 1) As Double For i1 = 1 To N For j1 = 1 To k + 1 xya(i1, j1) = XY(i1, j1) Next j1 Next i1 ''''''''''''''''''''''''''''''''''''''''''''' 'Recupera alguns resultats de l'estimació MQO ''''''''''''''''''''''''''''''''''''''''''''' ReDim esbmco(1 To k) As Double, tmco(1 To k) As Dou ble, ixpxxp(1 To k, 1 To N) For j1 = 1 To k esbmco(j1) = Sqr(S2 * IXPX(j1, j1)) tmco(j1) = B(j1) / esbmco(j1) Next j1 For j1 = 1 To k For j2 = 1 To k For i1 = 1 To N ixpxxp(j1, i1) = ixpxxp(j1, i1) + (G2SW EEP(j1, j2) * XY(i1, j2) * PES(i1)) Next i1 Next j2 Next j1 '''''''''''''''''''''''''''''''''''''''''' 'Definició variables comunes a cada mètode '''''''''''''''''''''''''''''''''''''''''' ReDim bboot(1 To k) As Double, bboot2(1 To k) As Do uble, bbiaix(1 To k) As Double, _ esbboot(1 To k) As Double, tboot(1 To 1000, 1 To k) As Double, pboot(1 To k) As Double, _ tvboot(1 To 10, 1 To k) As Double, yboot(1 To N) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' 'Inicialitza la rutina d'extracció pseudo-aleatòria ''''''''''''''''''''''''''''''''''''''''''''''''''' Rnd (-1) Randomize 123456 If BOOTSTRAP(1) Then 'Métode "remostratge dels re sidus" BOOTSTRAP(1) Dim epe As Double, yh As Double For i2 = 1 To 1000 '''''''''''''''''''''''''''''''''''''''''''' 'Nombres aleatoris per a fer les extraccions '''''''''''''''''''''''''''''''''''''''''''' For i1 = 1 To N a(i1) = Int((N * Rnd) + 1)

Page 72: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

71

Next i1 For i1 = 1 To N yboot(i1) = YHAT(i1) + E(a(i1)) Next i1 ReDim betaboot(1 To k) As Double For i1 = 1 To N For j1 = 1 To k betaboot(j1) = betaboot(j1) + (ixpxx p(j1, i1) * yboot(i1)) Next j1 Next i1 epe = 0 For i1 = 1 To N yh = 0 For j1 = 1 To k yh = yh + (XY(i1, j1) * PES(i1) * be taboot(j1)) Next j1 epe = epe + ((yboot(i1) - yh) ^ 2) Next i1 For j1 = 1 To k bboot(j1) = bboot(j1) + betaboot(j1) bboot2(j1) = bboot2(j1) + (betaboot(j1) ^ 2) tboot(i2, j1) = (betaboot(j1) - B(j1)) / (Sqr((epe / (N - k)) * G2SWEEP(j1, j1))) Next j1 Next i2 Call M1_12_1(bbiaix, bboot, bboot2, esbboot, pbo ot, tboot, tmco, tvboot, xya) Call M1_12_2(bbiaix, esbboot, esbmco, pboot, tbo ot, tvboot, 1) End If If BOOTSTRAP(2) Then 'Métode "aparellat" BOOTSTRA P(2) For j1 = 1 To k bboot(j1) = 0 bboot2(j1) = 0 Next j1 For i2 = 1 To 1000 '''''''''''''''''''''''''''''''''''''''''''' 'Nombres aleatoris per a fer les extraccions '''''''''''''''''''''''''''''''''''''''''''' For i1 = 1 To N a(i1) = Int((N * Rnd) + 1) Next i1 '''''''' 'Càlculs '''''''' ReDim G2SWEEP(1 To k + 1, 1 To k + 1) For i1 = 1 To N For j1 = 1 To k + 1 For j2 = j1 To k + 1 G2SWEEP(j1, j2) = G2SWEEP(j1, j2 ) + ((XY(a(i1), j1) * XY(a(i1), j2)) * PES(a(i1))) Next j2 Next j1 Next i1 For j1 = 1 To k + 1 For j2 = j1 + 1 To k + 1 G2SWEEP(j2, j1) = G2SWEEP(j1, j2) Next j2 Next j1 ERROR_COMBINACIO = False Call C_G2SWEEP(0, 1, G2SWEEP, N, k + 1, 0.00 000001, ERROR_COMBINACIO) For j1 = 1 To k bboot(j1) = bboot(j1) + G2SWEEP(j1, k + 1) bboot2(j1) = bboot2(j1) + (G2SWEEP(j1, k + 1) ^ 2) tboot(i2, j1) = (G2SWEEP(j1, k + 1) - B( j1)) / (Sqr((G2SWEEP(k + 1, k + 1) / (N - k)) * G2S WEEP(j1, j1))) Next j1 Next i2 Call M1_12_1(bbiaix, bboot, bboot2, esbboot, pbo ot, tboot, tmco, tvboot, xya) Call M1_12_2(bbiaix, esbboot, esbmco, pboot, tbo ot, tvboot, 2) End If Unload C2_Varis End Sub

Page 73: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

72

Private Sub M1_12_1(bbiaix, bboot, bboot2, esbboot, pboot, tboot, tmco, tvboot, xya) '''''''''''''''''''''''' 'obtenció dels resultats '''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, j1 As Integer, j2 As Integer ReDim XY(1 To 1000, 1 To k) For i2 = 1 To 1000 For j1 = 1 To k XY(i2, j1) = tboot(i2, j1) Next j1 Next i2 Call C_ORDENA(2, 1, k) For j1 = 1 To k bbiaix(j1) = (2 * B(j1)) - (bboot(j1) / 1000) esbboot(j1) = Sqr((bboot2(j1) - ((bboot(j1) ^ 2 ) / 1000)) / (1000 - 1)) For j2 = 1 To 5 i2 = IIf(j2 = 1, 5, IIf(j2 = 2, 10, IIf(j2 = 3, 25, IIf(j2 = 4, 50, 100)))) tvboot(j2, j1) = tboot(IND(i2, j1), j1) Next j2 For j2 = 5 To 1 Step -1 i2 = 1000 - IIf(j2 = 5, 5, IIf(j2 = 4, 10, IIf(j2 = 3, 25, IIf(j2 = 2, 50, 100)))) tvboot(j2 + 5, j1) = tboot(IND(i2, j1), j1) Next j2 Next j1 For i2 = 1 To 1000 For j1 = 1 To k If Abs(tmco(j1)) < Abs(tboot(i2, j1)) Then pboot(j1) = pboot(j1) + 1 Next j1 Next i2 ''''''''''''''''''''''''''''''' 'Recupera la matriu XY original ''''''''''''''''''''''''''''''' ReDim XY(1 To N, 1 To k + 1) For i1 = 1 To N For j1 = 1 To k + 1 XY(i1, j1) = xya(i1, j1) Next j1 Next i1 End Sub Private Sub M1_12_2(bbiaix, esbboot, esbmco, pboot, tboot, tvboot, opcio As Integer) ''''''''''''''''''''' 'Escriptura Resultats ''''''''''''''''''''' Dim i1 As Integer, j1 As Integer, j2 As Integer, ti tol1 As String ReDim R(1 To k + 2, 1 To 7) R(1, 1) = "Variable" R(1, 2) = "Parámetro" & Chr(10) & "(corr. sesgo)" R(1, 3) = "err. es." & Chr(10) & "'bootstrap'" R(1, 4) = "Valor t" & Chr(10) & "'bootstrap'" R(1, 5) = "Intervalo 'bootstrap-t'" & Chr(10) & "(s ig.=" & Format(SIG, "0.00") & ")" R(1, 7) = "P-value" & Chr(10) & "'bootstrap'" For j1 = 1 To k R(j1 + 2, 1) = "b" & j1 & "(" & LVAR(j1, 2) & " )" R(j1 + 2, 2) = bbiaix(j1) R(j1 + 2, 3) = esbboot(j1) R(j1 + 2, 4) = bbiaix(j1) / esbboot(j1) R(j1 + 2, 5) = B(j1) - (tboot(IND(1000 - (1000 * SIG / 2), j1), j1) * esbmco(j1)) R(j1 + 2, 6) = B(j1) - (tboot(IND(1000 * SIG / 2, j1), j1) * esbmco(j1)) R(j1 + 2, 7) = pboot(j1) / 1000 R(j1 + 2, 7) = IIf(R(j1 + 2, 7) < 0.0001, "< 0, 0001", R(j1 + 2, 7)) Next j1 ReDim aux(1 To 1, 1 To 1) aux(1, 1) = 0 titol1 = "ESTIMACIÓN 'BOOTSTRAP' (Método: " & IIf(o pcio = 1, "'remuestreo por residuos')", "'pareado') ") Call M1_ESCRIPTURA(12, titol1, aux) aux(1, 1) = 1 ReDim R(1 To 11, 1 To k + 1) R(1, 1) = "Percentiles" For j1 = 1 To k

Page 74: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

73

R(1, j1 + 1) = "b" & j1 & "(" & LVAR(j1, 2) & " )" Next j1 R(2, 1) = 0.005 R(3, 1) = 0.01 R(4, 1) = 0.025 R(5, 1) = 0.05 R(6, 1) = 0.1 R(7, 1) = 0.9 R(8, 1) = 0.95 R(9, 1) = 0.975 R(10, 1) = 0.99 R(11, 1) = 0.995 For j2 = 1 To 10 For j1 = 1 To k R(j2 + 1, j1 + 1) = tvboot(j2, j1) Next j1 Next j2 Call M1_ESCRIPTURA(121, "PERCENTILES 'BOOTSTRAP-t'" , aux) End Sub Private Sub M1_21(LLARG) ''''''''' 'RESIDUS' ''''''''' Dim dim1 As Integer, h1 As Double, h2 As Double, i1 As Integer, i2 As Integer, j1 As Integer, l As Int eger, _ maxim1 As Integer, resta1 As Integer, tit As St ring ReDim aux(1 To 2), raux(1 To N, 1 To 7) As Double Sheets(FULL_R).Activate LLARG = 1 If IY <> 0 Then With Cells(1, 11) aux(1) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = LOBS(LLARG) .Columns.AutoFit aux(2) = .ColumnWidth .Clear .ColumnWidth = aux(1) End With LLARG = IIf(aux(2) > 3 * 9.57, 3, IIf(aux(2) > 2 * 9.57, 2, 1)) End If l = LLARG aux(1) = Application.TInv(SIG, GL(2)) For i1 = 1 To N h1 = (1 + HAT(i1)) / PES(i1) h2 = (1 - HAT(i1)) / PES(i1) raux(i1, 1) = XY(i1, k + 1) raux(i1, 2) = YHAT(i1) raux(i1, 3) = Sqr(S2 * HAT(i1) / PES(i1)) raux(i1, 4) = YHAT(i1) - (aux(1) * Sqr(S2 * h1) ) raux(i1, 5) = YHAT(i1) + (aux(1) * Sqr(S2 * h1) ) raux(i1, 6) = E(i1) raux(i1, 7) = Sqr(S2 * h2) Next i1 Set RG = Range(Cells(1, 20), Cells(N, 27)) 'Def ineix el rang' For i1 = 1 To N RG.Columns(1).Rows(i1) = i1 RG.Columns(2).Rows(i1) = E(i1) RG.Columns(3).Rows(i1) = XY(i1, k + 1) RG.Columns(4).Rows(i1) = YHAT(i1) Next i1 Call C_ORDENA(3, 1, 1) 'Ord ena els residus' For i1 = 1 To N RG.Columns(5).Rows(i1) = RG.Columns(2).Rows(IND (i1, 1)) RG.Columns(6).Rows(i1) = Application.NormSInv(( i1 - (3 / 8)) / (N + 0.25)) RG.Columns(7).Rows(i1) = Application.NormInv((( i1 - (3 / 8)) / (N + 0.25)), 0, Sqr(S2)) Next i1 Sheets(FULL).Activate dim1 = IIf(N <= 75, N, 75) maxim1 = IIf(N <= 75, 1, Int(N / 75)) resta1 = IIf(N <= 75, 0, N - (maxim1 * 75))

Page 75: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

74

If resta1 <> 0 Then maxim1 = maxim1 + 1 ReDim nomscol(1 To 7 + l) nomscol(1) = LVAR(0, 2) nomscol(1 + l) = LVAR(NY, 1) nomscol(2 + l) = "Predicción" nomscol(3 + l) = "err. es." & Chr(10) & "Predicción " nomscol(4 + l) = "Intervalo Predicción" & Chr(10) & "(sig.=" & Format(SIG, "0.00") & ")" nomscol(6 + l) = "Residuo" nomscol(7 + l) = "err. es." & Chr(10) & "Residuo" For i2 = 1 To maxim1 ReDim R(1 To IIf(i2 < maxim1, dim1, IIf(resta1 = 0, dim1, resta1)) + 2, 1 To 7 + l) For i1 = 1 To IIf(i2 < maxim1, dim1, IIf(resta1 = 0, dim1, resta1)) R(i1 + 2, 1) = LOBS(i1 + ((i2 - 1) * 75)) For j1 = 1 + l To 7 + l R(i1 + 2, j1) = raux(i1 + ((i2 - 1) * 7 5), j1 - l) Next j1 Next i1 For i1 = 1 To 7 + l R(1, i1) = nomscol(i1) Next i1 Call M1_ESCRIPTURA(21, "RESIDUOS Y PREDICCIONES " & IIf(i2 <> 1, "(cont.) ", ""), aux) Next i2 Call M1_GRAFICS(1) End Sub Private Sub M1_22(LLARG) ''''''''''''''''''''''''' 'INFLUÈNCIA I ATIPICITAT' ''''''''''''''''''''''''' Dim aux(), dim1 As Integer, dim2 As Integer, h As D ouble, i1 As Integer, i11 As Integer, _ j1 As Integer, j2 As Integer, j22 As Integer, k 1 As Integer, l As Integer, _ maxim1 As Integer, maxim2 As Integer, resta1 As Integer, resta2 As Integer, si As Double, tit As S tring ReDim aux(1 To 2) If Not OPT(21, 0) Then LLARG = 1 If IY <> 0 Then With Cells(1, 11) aux(1) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = LOBS(LLARG) .Columns.AutoFit aux(2) = .ColumnWidth .Clear .ColumnWidth = aux(1) End With LLARG = IIf(aux(2) > 3 * 9.57, 3, IIf(aux(2) > 2 * 9.57, 2, 1)) End If End If l = LLARG If k + 1 <= 9 Then OPT(22, 2) = True If k + l > 9 Then OPT(0, 0) = 12 With C2_Varis .Aceptar.Top = 45 .Cancelar.Top = 45 .Caption = "Modelos de Regresión: Influencia y atipicidad" .c01.Caption = "Residuos, Leverage, Cook y DFF ITS" .c01.Locked = True .c02.Caption = "DFBETAS" .c02.Value = False .c03.Visible = False .c04.Visible = False .c05.Visible = False .Frame0.Height = 35 With .MultiPage1 .Height = 45 .Style = fmTabStyleNone .Value = 0 End With .Height = 90 .Show End With If SORTIR Then SORTIR = False Unload C2_Varis

Page 76: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

75

End If ReDim aux(1 To 6 + l), nomscol(1 To 6 + l), raux(1 To N, 1 To 6 + IIf(OPT(22, 2), k, 0)) As Double aux(1 + l) = 1.644853 aux(2 + l) = Abs(Application.TInv(0.05, N - k)) aux(3 + l) = Abs(Application.TInv(0.05, N - k - 1)) aux(4 + l) = 2 * k / N aux(5 + l) = 1 aux(6 + l) = 2 * Sqr(k / N) For i1 = 1 To N h = (1 - HAT(i1)) / PES(i1) si = Sqr((S2 * GL(2) / (GL(2) - 1)) - (E(i1) ^ 2) / ((GL(2) - 1) * h)) raux(i1, 1) = E(i1) / Sqr(S2 / PES(i1)) raux(i1, 2) = E(i1) / Sqr(S2 * h) raux(i1, 3) = E(i1) / (si * Sqr(h)) raux(i1, 4) = HAT(i1) raux(i1, 5) = (E(i1) ^ 2) * HAT(i1) / (k * S2 * (h ^ 2) * PES(i1)) raux(i1, 6) = E(i1) * Sqr(HAT(i1) / PES(i1)) / (si * h) If OPT(22, 2) Then ReDim a1(1 To k) As Double For j1 = 1 To k For k1 = 1 To k a1(j1) = a1(j1) + ((XY(i1, k1) * IXP X(k1, j1)) * E(i1) / (si * h * Sqr(IXPX(j1, j1)))) Next k1 Next j1 For j1 = 1 To k raux(i1, j1 + 6) = a1(j1) Next j1 End If Next i1 Sheets(FULL_R).Activate Set RG = Range(Cells(1, 20), Cells(N, 27)) 'Defi neix el rang' For i1 = 1 To N RG.Columns(1).Rows(i1) = i1 For j1 = 2 To 7 RG.Columns(j1).Rows(i1) = raux(i1, j1 - 1) Next j1 Next i1 Sheets(FULL).Activate dim1 = IIf(N <= 75, N, 75) maxim1 = IIf(N <= 75, 1, Int(N / 75)) resta1 = IIf(N <= 75, 0, N - (maxim1 * 75)) If resta1 <> 0 Then maxim1 = maxim1 + 1 nomscol(1) = LVAR(0, 2) nomscol(1 + l) = "Residuo" & Chr(10) & "Estandariz. " nomscol(2 + l) = "Residuo" & Chr(10) & "Student." nomscol(3 + l) = "Res. Student." & Chr(10) & "Corre gido" nomscol(4 + l) = "Leverage" nomscol(5 + l) = "Distancia de" & Chr(10) & "Cook" nomscol(6 + l) = "DFFITS" For i1 = 1 To maxim1 ReDim R(1 To IIf(i1 < maxim1, dim1, IIf(resta1 = 0, dim1, resta1)) + 2, 1 To 6 + l) For i11 = 1 To IIf(i1 < maxim1, dim1, IIf(resta 1 = 0, dim1, resta1)) R(i11 + 2, 1) = LOBS(i11 + ((i1 - 1) * 75)) For j1 = 1 + l To 6 + l R(i11 + 2, j1) = raux(i11 + ((i1 - 1) * 75), j1 - l) Next j1 Next i11 For i11 = 1 To 6 + l R(1, i11) = nomscol(i11) Next i11 Call M1_ESCRIPTURA(22, "ATIPICIDAD E INFLUENCIA " & IIf(i1 <> 1, "(cont.) ", "") & tit, aux) Next i1 If Not OPT(22, 2) Then GoTo salta dim2 = IIf(k + l <= 10, k + l, 10) maxim2 = IIf(k + l <= 10, 1, Int((k + l) / 10)) resta2 = IIf(k + l <= 10, 0, k + l - (maxim2 * 10) + 1) If resta2 <> 0 Then maxim2 = maxim2 + 1 ReDim aux(1 To dim2) For i1 = 1 + l To dim2 aux(i1) = 2 / Sqr(N) Next i1 For j2 = 1 To maxim2 ReDim nomscol(1 To IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2)))

Page 77: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

76

nomscol(1) = "Observación" For j22 = 1 + l To IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2)) nomscol(j22) = "b" & (j22 - l - IIf(j2 = 1, 0, 1)) + ((j2 - 1) * 10) & _ Chr(10) & _ "(" & LVAR(j22 - l - IIf(j2 = 1, 0, 1) + ((j2 - 1) * 10), 2) & ")" Next j22 For i1 = 1 To maxim1 ReDim R(1 To IIf(i1 < maxim1, dim1, IIf(res ta1 = 0, dim1, resta1)) + 2, 1 To IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) For i11 = 1 To IIf(i1 < maxim1, dim1, IIf(r esta1 = 0, dim1, resta1)) R(i11 + 2, 1) = LOBS(i11 + ((i1 - 1) * 75)) For j22 = 1 + l To IIf(j2 = 1, dim2, II f(resta2 <> 0, resta2, dim2)) R(i11 + 2, j22) = raux(i11 + ((i1 - 1) * 75), j22 + 6 - l - IIf(j2 = 1, 0, 1) + ((j2 - 1) * 10)) Next j22 Next i11 For i11 = 1 To IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2)) R(1, i11) = nomscol(i11) Next i11 Call M1_ESCRIPTURA(22, "INFLUENCIA (DFBETAS )" & IIf(i1 <> 1 Or j2 <> 1, "(cont.) ", ""), aux) Next i1 Next j2 salta: Call M1_GRAFICS(2) End Sub Private Sub M1_23(opcio As Integer) ''''''''''''''''''' 'RESIDUS RECURSIUS' ''''''''''''''''''' Dim a As Double, aux(1 To 1), aux1 As Double, aux2 As Double, c0 As Double, den As Double, dim1 As Int eger, _ i1 As Integer, i2 As Integer, j1 As Integer, k1 As Integer, l1 As Integer, m() As Double, _ maxim1 As Integer, resta1 As Integer, sigma As Double, v As Boolean, yh As Double ReDim br(1 To k) As Double, raux(1 To N, 1 To 7) As Double, X(1 To k) As Double aux1 = 0 aux2 = 0 raux(k, 2) = 0 raux(k, 5) = 0 For i1 = k + 1 To N ReDim m(1 To k + 1, 1 To k + 1) For l1 = 1 To i1 - 1 For j1 = 1 To k + 1 For k1 = j1 To k + 1 m(j1, k1) = m(j1, k1) + (XY(l1, j1) * XY(l1, k1)) Next k1 Next j1 Next l1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, IC, m, i1 - 1, k + 1, 0.00000 001, False) For j1 = 1 To k X(j1) = XY(i1, j1) br(j1) = m(j1, k + 1) Next j1 den = 0 For j1 = 1 To k For k1 = 1 To k den = den + (X(k1) * m(k1, j1) * X(j1)) Next k1 Next j1 den = den + 1 yh = 0 For j1 = 1 To k yh = yh + (XY(i1, j1) * br(j1)) Next j1 raux(i1, 1) = (XY(i1, k + 1) - yh) / Sqr(den) aux1 = aux1 + raux(i1, 1) aux2 = aux2 + (raux(i1, 1) ^ 2) sigma = Sqr((aux2 - ((aux1 ^ 2) / (N - k))) / ( N - k - 1)) Next i1 For i1 = k + 1 To N raux(i1, 2) = raux(i1 - 1, 2) + raux(i1, 1) raux(i1, 5) = raux(i1 - 1, 5) + raux(i1, 1) ^ 2 Next i1 Call M1_23_1(c0) a = IIf(SIG = 0.01, 1.143, 0.948) For i1 = k + 1 To N

Page 78: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

77

raux(i1, 2) = raux(i1, 2) / sigma raux(i1, 3) = -(a * Sqr(N - k) + ((2 * a * (i1 - k)) / Sqr(N - k))) raux(i1, 4) = -raux(i1, 3) raux(i1, 5) = raux(i1, 5) / aux2 raux(i1, 6) = -c0 + ((i1 - k) / (N - k)) raux(i1, 7) = c0 + ((i1 - k) / (N - k)) Next i1 Sheets(FULL_R).Activate Set RG = Range(Cells(1, 20), Cells(N, 27)) 'Defin eix el rang' For i1 = k + 1 To N RG.Columns(1).Rows(i1) = i1 RG.Columns(2).Rows(i1) = raux(i1, 1) For j1 = 1 To 3 RG.Columns(j1 + 2).Rows(i1) = raux(i1, j1 + 1) RG.Columns(j1 + 5).Rows(i1) = raux(i1, j1 + 4) Next j1 Next i1 Sheets(FULL).Activate dim1 = IIf(N <= 75, N, 75) maxim1 = IIf(N <= 75, 1, Int(N / 75)) resta1 = IIf(N <= 75, 0, N - (maxim1 * 75)) If resta1 <> 0 Then maxim1 = maxim1 + 1 For i2 = 1 To maxim1 ReDim R(1 To IIf(i2 < maxim1, dim1, IIf(resta1 = 0, dim1, resta1)) + 2, 1 To 8) R(1, 1) = "Observación" R(1, 2) = "Residuo" & Chr(10) & "Recursivo" R(1, 3) = "CUSUM" R(1, 4) = "Intervalo CUSUM" & Chr(10) & "(sig.= " & IIf(SIG = 0.01, "0.01", "0.05") & ")" R(1, 6) = "CUSUMSQ" R(1, 7) = "Intervalo CUSUMSQ" & Chr(10) & "(sig .=" & IIf(SIG = 0.01, "0.01", "0.05") & ")" For i1 = 1 To IIf(i2 < maxim1, dim1, IIf(resta1 = 0, dim1, resta1)) If i2 = 1 And i1 <= k Then For j1 = 1 To 8 R(i1 + 2, j1) = "'." Next j1 Else R(i1 + 2, 1) = i1 + ((i2 - 1) * 75) For j1 = 1 To 7 R(i1 + 2, j1 + 1) = raux(i1 + ((i2 - 1) * 75), j1) Next j1 End If Next i1 Call M1_ESCRIPTURA(23, "INDICADORES DE ESTABILI DAD DE LA MUESTRA" & IIf(i2 <> 1, " (cont.)", ""), aux) Next i2 Call M1_GRAFICS(3) End Sub Private Sub M1_23_1(c0) '''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A CALCULAR C0 CUSUMSQ' '''''''''''''''''''''''''''''''''''' Dim c(1 To 100, 1 To 2) As Double, dim1 As Integer ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' c(1, 1) = 0.475: c(2, 1) = 0.50855: c(3, 1) = 0.467 02: c(4, 1) = 0.44641: c(5, 1) = 0.42174 c(6, 1) = 0.40045: c(7, 1) = 0.38294: c(8, 1) = 0.3 6697: c(9, 1) = 0.35277: c(10, 1) = 0.34022 c(11, 1) = 0.32894: c(12, 1) = 0.31869: c(13, 1) = 0.39035: c(14, 1) = 0.30081: c(15, 1) = 0.29296 c(16, 1) = 0.2857: c(17, 1) = 0.27897: c(18, 1) = 0 .2727: c(19, 1) = 0.26685: c(20, 1) = 0.26137 c(21, 1) = 0.25622: c(22, 1) = 0.25136: c(23, 1) = 0.24679: c(24, 1) = 0.24245: c(25, 1) = 0.23835 c(26, 1) = 0.23445: c(27, 1) = 0.23074: c(28, 1) = 0.22721: c(29, 1) = 0.22383: c(30, 1) = 0.22061 c(31, 1) = 0.21752: c(32, 1) = 0.21457: c(33, 1) = 0.21173: c(34, 1) = 0.20901: c(35, 1) = 0.20639 c(36, 1) = 0.20387: c(37, 1) = 0.20144: c(38, 1) = 0.1991: c(39, 1) = 0.19684: c(40, 1) = 0.19465 c(41, 1) = 0.19254: c(42, 1) = 0.1905: c(43, 1) = 0 .18852: c(44, 1) = 0.18661: c(45, 1) = 0.18475 c(46, 1) = 0.18295: c(47, 1) = 0.1812: c(48, 1) = 0 .1795: c(49, 1) = 0.17785: c(50, 1) = 0.17624 c(51, 1) = 0.17468: c(52, 1) = 0.17316: c(53, 1) = 0.17168: c(54, 1) = 0.17024: c(55, 1) = 0.16884 c(56, 1) = 0.16746: c(57, 1) = 0.16613: c(58, 1) = 0.16482: c(59, 1) = 0.16355: c(60, 1) = 0.1623 c(62, 1) = 0.1599: c(64, 1) = 0.1576: c(66, 1) = 0. 1554: c(68, 1) = 0.15329: c(70, 1) = 0.15127 c(72, 1) = 0.14932: c(74, 1) = 0.14745: c(76, 1) = 0.14565: c(78, 1) = 0.14392: c(80, 1) = 0.14224 c(82, 1) = 0.14063: c(84, 1) = 0.13907: c(86, 1) = 0.13756: c(88, 1) = 0.1361: c(90, 1) = 0.13468 c(92, 1) = 0.13331: c(94, 1) = 0.13198: c(96, 1) = 0.1307: c(98, 1) = 0.12944: c(100, 1) = 0.12823 ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' c(1, 2) = 0.495: c(2, 2) = 0.59596: c(3, 2) = 0.579 : c(4, 2) = 0.5421: c(5, 2) = 0.51576 c(6, 2) = 0.48988: c(7, 2) = 0.46761: c(8, 2) = 0.4 4819: c(9, 2) = 0.43071: c(10, 2) = 0.41517 c(11, 2) = 0.40122: c(12, 2) = 0.38856: c(13, 2) = 0.37703: c(14, 2) = 0.36649: c(15, 2) = 0.35679 c(16, 2) = 0.34784: c(17, 2) = 0.33953: c(18, 2) = 0.33181: c(19, 2) = 0.32459: c(20, 2) = 0.31784 c(21, 2) = 0.31149: c(22, 2) = 0.30552: c(23, 2) = 0.29989: c(24, 2) = 0.29456: c(25, 2) = 0.28951

Page 79: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

78

c(26, 2) = 0.28472: c(27, 2) = 0.28016: c(28, 2) = 0.27582: c(29, 2) = 0.27168: c(30, 2) = 0.26772 c(31, 2) = 0.26393: c(32, 2) = 0.2603: c(33, 2) = 0 .25683: c(34, 2) = 0.25348: c(35, 2) = 0.25027 c(36, 2) = 0.24718: c(37, 2) = 0.24421: c(38, 2) = 0.24134: c(39, 2) = 0.23857: c(40, 2) = 0.23589 c(41, 2) = 0.2331: c(42, 2) = 0.23081: c(43, 2) = 0 .22839: c(44, 2) = 0.22605: c(45, 2) = 0.22377 c(46, 2) = 0.22157: c(47, 2) = 0.21943: c(48, 2) = 0.21735: c(49, 2) = 0.21534: c(50, 2) = 0.21337 c(51, 2) = 0.21146: c(52, 2) = 0.20961: c(53, 2) = 0.2078: c(54, 2) = 0.20604: c(55, 2) = 0.20432 c(56, 2) = 0.20265: c(57, 2) = 0.20101: c(58, 2) = 0.19942: c(59, 2) = 0.19786: c(60, 2) = 0.19635 c(62, 2) = 0.19341: c(64, 2) = 0.19061: c(66, 2) = 0.18792: c(68, 2) = 0.18535: c(70, 2) = 0.18288 c(72, 2) = 0.18051: c(74, 2) = 0.17823: c(76, 2) = 0.17604: c(78, 2) = 0.17392: c(80, 2) = 0.17188 c(82, 2) = 0.16992: c(84, 2) = 0.16802: c(86, 2) = 0.16618: c(88, 2) = 0.1644: c(90, 2) = 0.16268 c(92, 2) = 0.16101: c(94, 2) = 0.1594: c(96, 2) = 0 .15783: c(98, 2) = 0.15631: c(100, 2) = 0.15483 ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' dim1 = Int((N - k) / 2) - 1 If dim1 <= 60 Then dim1 = dim1 ElseIf dim1 > 60 And dim1 <= 100 Then dim1 = Application.Even(dim1) Else dim1 = 100 End If c0 = c(dim1, IIf(SIG = 0.01, 2, 1)) End Sub Private Sub M1_ESCRIPTURA(opcio As Integer, TITOL A s String, m()) ''''''''''''''''''''''''''' 'ESCRIPTURA DELS RESULTATS' ''''''''''''''''''''''''''' Sheets(FULL_R).Activate Dim i1 As Integer, j1 As Integer, j2 As Integer, k1 As Integer Dim c(1 To 2) As Integer, m1, m2 c(1) = UBound(R, 1) c(2) = UBound(R, 2) With Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 10) ) .ColumnWidth = 9.5 With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter .Interior.ColorIndex = 2 .RowHeight = 11 .VerticalAlignment = xlCenter End With With Cells(F - 1, 1) .Font.Bold = True .HorizontalAlignment = xlLeft .Value = TITOL End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) With .Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium End With With .Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium End With .Interior.ColorIndex = 37 .Value = R End With For i1 = 1 To c(2) With Range(Cells(F, i1), Cells(F + IIf(opcio <> 0 And opcio <> 2 And opcio <> 121, 1, 0), i1)) If opcio <> 2 Then .Borders(xlEdgeBottom).Lin eStyle = xlContinuous .Font.Bold = True If opcio <> 7 And opcio <> 121 Then .MergeCel ls = True .WrapText = True End With Next i1 With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Font.Bold = True .HorizontalAlignment = xlLeft End With ''''''''''''''''''''''''''''''''''''''''' 'Escriptura característica de cada opció' '''''''''''''''''''''''''''''''''''''''''

Page 80: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

79

If opcio = 0 Then 'MATRIUS With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Borders(xlRight).LineStyle = xlContinuous If Left(TITOL, 11) = "MATRIZ DE V" Or Left(TIT OL, 26) = "MATRIZ DE CORRELACIONES (P" Then .Charac ters(1, 1).Font.Name = "Symbol" .Font.Bold = True .HorizontalAlignment = xlLeft .VerticalAlignment = xlCenter End With If Left(TITOL, 11) = "MATRIZ DE V" Or Right(TITO L, 11) = "PARÁMETROS)" Then With Range(Cells(F, 2), Cells(F, c(2))).Chara cters(1, 1).Font .Name = "Symbol" .Bold = True End With End If If Right(TITOL, 2) = "S)" Then Range(Cells(F, 2), Cells(F + c(1) - 1, c(2))) .NumberFormat = "0.0000" ElseIf Left(TITOL, 6) = "FACTOR" Then Range(Cells(F, 2), Cells(F + c(1) - 1, c(2))) .NumberFormat = "###,0.000" ElseIf Left(TITOL, 6) = "NÚMERO" Then Range(Cells(F, 3), Cells(F + c(1) - 1, 3)).Nu mberFormat = "###,0.000" ElseIf Left(TITOL, 6) = "PROPOR" Then With Range(Cells(F, 2), Cells(F, c(2))).Chara cters(1, 1).Font .Name = "Symbol" .Bold = True End With Range(Cells(F, 2), Cells(F + c(1) - 1, c(2))) .NumberFormat = "0.0000" End If If Right(TITOL, 3) = "ES)" Then Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1, c(2))).Borders(xlEdgeTop).LineStyle = xlDash If R(1, c(2)) = LVAR(k + 1, 2) Then Range(Cel ls(F, c(2)), Cells(F + c(1) - 1, c(2))).Borders(xlEdgeLeft).LineStyle = xlDash End If If m(1) = 1 Then ActiveWindow.SelectedSheets.HPa geBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 1 Then 'ESTADISTICA DESCRIPTIVA Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter If TITOL <> "" Then Range(Cells(F, 2), Cells(F + c(1) - 1, IIf(NPES = 0, 2, 3))).NumberFormat = "## #,0" k1 = IIf(NPES <> 0, 1, 0) For i1 = 2 To c(1) - k1 For j1 = IIf(TITOL <> "", IIf(NPES = 0, 3, 4 ), 2) To c(2) With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R(i1 , j1)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j1)) < 1000 And Abs(R(i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000 " End With Next j1 Next i1 Range(Cells(F + c(1) - 1 - k1, 1), Cells(F + c(1 ) - 1 - k1, c(2))).Borders(xlEdgeTop).LineStyle = x lDash If NPES <> 0 Then With Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1, c(2))) .Borders(xlEdgeTop).LineStyle = xlContinuou s .MergeCells = True End With End If If m(1) = 1 Then ActiveWindow.SelectedSheets.HPa geBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 2 Then 'ANÀLISI DE LA VARIÀNCIA k1 = IIf(NPES <> 0, 1, 0) Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eBottom).LineStyle = xlContinuous Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eBottom).Weight = xlMedium For j1 = 1 To 4 Step 3 With Range(Cells(F, j1), Cells(F, j1 + 2)) .Font.Bold = True .HorizontalAlignment = IIf(j1 = 1, xlLeft, xlRight) .MergeCells = True End With Next j1 With Range(Cells(F + 1, 1), Cells(F + 1, c(2))) .Borders(xlEdgeBottom).LineStyle = xlContinuou s .Font.Bold = True End With For i1 = 3 To 5 For j1 = 2 To 4 Step 2 With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R(i1 , j1)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j1)) < 1000 And Abs(R(i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000 " End With Next j1 Next i1

Page 81: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

80

Range(Cells(F + 2, 3), Cells(F + c(1) - 1 - k1, 3)).NumberFormat = "###,0" With Range(Cells(F + 2, 5), Cells(F + 2, 5)) If Abs(R(3, 5)) >= 100 And Abs(R(3, 5)) < 1 0 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(3, 5)) < 100 And Abs(R(3, 5)) >= 1 0 ^ (-6) Then .NumberFormat = "##0.000000" End With Range(Cells(F, 6), Cells(F + c(1) - 1 - k1, 6)). NumberFormat = "0.0000" For j1 = 1 To 6 With Cells(F + c(1) - 1 - k1, j1) If j1 = 1 Or j1 = 3 Or j1 = 5 Then If j1 = 1 Then .Characters(1, 1).Font.N ame = "Symbol" If j1 > 1 Then .Characters(1, IIf(j1 = 3, 3, 7)).Font.Bold = True .HorizontalAlignment = xlRight .VerticalAlignment = xlCenter Else .HorizontalAlignment = xlLeft If R(c(1) - k1, j1) >= 100 And R(c(1) - k1, j1) < 10 ^ 9 Then .NumberFormat = "###,0.00" If R(c(1) - k1, j1) < 100 And R(c(1) - k1, j1) >= 10 ^ (-6) Then .NumberFormat = "##0.0000 00" If j1 > 2 Then .NumberFormat = "0.0000" End If End With Next j1 Range(Cells(F + c(1) - 1 - k1, 1), Cells(F + c(1 ) - 1 - k1, c(2))).Borders(xlEdgeTop).LineStyle = xlContinuous If NPES <> 0 Then Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1, c(2))).Borders(xlEdgeTop).LineStyle = xlContin uous Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1, 3)).MergeCells = True With Range(Cells(F + c(1) - 1, 4), Cells(F + c(1) - 1, c(2))) .Font.Bold = True .HorizontalAlignment = xlRight .MergeCells = True End With End If ElseIf opcio = 3 Or opcio = 8 Then 'ESTIMACIÓ MQO, ESTIMACIÓ WHITE Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter With Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).Characters(1, 1).Font .Name = "Symbol" .Bold = True End With If opcio = 3 Then Range(Cells(F, 3), Cells(F + c (1) - 1, 3)).NumberFormat = "0.000000" j1 = IIf(opcio = 3, 5, 4) Range(Cells(F, j1), Cells(F + c(1) - 1, j1)).Num berFormat = "#####0.000" Range(Cells(F, j1 + 1), Cells(F + c(1) - 1, j1 + 1)).NumberFormat = "0.0000" Range(Cells(F, j1 + 2), Cells(F + 1, j1 + 3)).Me rgeCells = True For j1 = 2 To 8 Step 2 j2 = j1 If (opcio = 3 And j1 = 6) Then j2 = j1 + 1 If (opcio = 8 And (j1 = 4 Or j1 = 8)) Then j 2 = j1 - 1 For i1 = 2 To c(1) With Cells(F + i1 - 1, j2) If Abs(R(i1, j2)) >= 1000 And Abs(R(i 1, j2)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j2)) < 1000 And Abs(R(i1 , j2)) >= 10 ^ (-6) Then .NumberFormat = "##0.00000 0" End With Next i1 Next j1 If m(1, 1) = 1 Then ActiveWindow.SelectedSheets. HPageBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 4 Then 'PREDICCIÓ EX-POST' Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter If m(1) = 2 Then Range(Cells(F, 1), Cells(F, 2)) .MergeCells = True Range(Cells(F, c(2) - 1), Cells(F, c(2))).MergeC ells = True For i1 = 1 To c(1) - IIf(m(5) = 0, 9, 2) j1 = F + 1 + i1 If m(1) = 2 Then Range(Cells(j1, 1), Cells(j 1, 2)).MergeCells = True For j1 = m(1) + 1 To c(2) With Cells(F + 1 + i1, j1) If j1 <> c(2) - 2 Then If Abs(R(i1 + 2, j1)) >= 1000 And A bs(R(i1 + 2, j1)) < 10 ^ 9 Then .NumberFormat = "## #,0.00" If Abs(R(i1 + 2, j1)) < 1000 And Ab s(R(i1 + 2, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" Else .NumberFormat = "###0.00%" End If End With Next j1 Next i1 If m(5) = 0 Then Range(Cells(F + c(1) - 7, 1), Cells(F + c(1) - 7, c(2))).Borders(xlEdgeTop).LineStyle = xlContin uous j1 = IIf(m(3) = 0, 3, 4) With Range(Cells(F + c(1) - 7, j1), Cells(F + c(1) - 7, IIf(m(3) = 1, j1 + 2, j1 + 3))) .Borders(xlEdgeBottom).LineStyle = xlContin uous

Page 82: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

81

.Font.Bold = True .HorizontalAlignment = xlCenter .MergeCells = True End With Range(Cells(F + c(1) - 7, j1), Cells(F + c(1) - 1, j1)).Borders(xlLeft).LineStyle = xlContinuous i1 = IIf(m(3) = 1, j1 + 2, j1 + 3) Range(Cells(F + c(1) - 7, i1), Cells(F + c(1) - 1, i1)).Borders(xlRight).LineStyle = xlContinuou s Range(Cells(F + c(1) - 3, j1), Cells(F + c(1) - 3, i1)).Borders(xlEdgeTop).LineStyle = xlDash For i1 = 1 To 6 With Range(Cells(F + c(1) - 7 + i1, j1), Cells(F + c(1) - 7 + i1, j1 + 1)) .Font.Bold = True .HorizontalAlignment = xlRight .MergeCells = True End With With Cells(F + c(1) - 7 + i1, j1 + 2) .HorizontalAlignment = xlLeft If R(c(1) - 6 + i1, j1 + 2) >= m1 Then .NumberFormat = "#####0.000000" End With Next i1 End If ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) ElseIf opcio = 5 Then 'RESTRICCIONS LINEALS Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter If m(1) = "test" Then For i1 = 1 To c(1) With Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1, m(2))) .HorizontalAlignment = xlLeft .MergeCells = True End With If i1 > 2 Then With Cells(F + i1 - 1, 1) For j1 = 1 To Len(R(i1, 1)) If Mid(R(i1, 1), j1, 1) = "b" Th en .Characters(j1, 1).Font.Name = "Symbol" Next j1 .Font.Bold = True End With End If Next i1 Range(Cells(F + 1, c(2) - 2), Cells(F + c(1) - 1, c(2) - 2)).NumberFormat = "###,0.000" Range(Cells(F + 1, c(2) - 1), Cells(F + c(1) - 1, c(2) - 1)).NumberFormat = "0" Range(Cells(F + 1, c(2)), Cells(F + c(1) - 1, c(2))).NumberFormat = "0.0000" If m(3) = 1 Then ActiveWindow.SelectedSheets. HPageBreaks.Add (Cells(F + c(1), 1)) Else With Cells(F - 1, 1) For j1 = 25 To Len(TITOL) If Mid(TITOL, j1, 1) = "b" And Mid(TITO L, j1 - 1, 1) <> "a" Then .Characters(j1, 1).Font.N ame = "Symbol" Next j1 .Font.Bold = True End With With Range(Cells(F + 1, 1), Cells(F + c(1) - 3, 1)).Characters(1, 1).Font .Name = "Symbol" .Bold = True End With Range(Cells(F, 6), Cells(F, 7)).MergeCells = True Range(Cells(F, 4), Cells(F + c(1) - 1, 4)).Nu mberFormat = "###,0.000" Range(Cells(F, 5), Cells(F + c(1) - 1, 5)).Nu mberFormat = "0.0000" For j1 = 2 To 8 Step 2 j2 = j1 If (j1 = 4 Or j1 = 8) Then j2 = j1 - 1 For i1 = 2 To c(1) - 2 With Cells(F + i1 - 1, j2) If Abs(R(i1, j2)) >= 1000 And Abs(R (i1, j2)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j2)) < 1000 And Abs(R( i1, j2)) >= 10 ^ (-6) Then .NumberFormat = "##0.000 000" End With Next i1 Next j1 For j1 = 1 To 7 With Cells(F + c(1) - 2, j1) .Borders(xlEdgeTop).LineStyle = xlConti nuous If j1 = 1 Or j1 = 6 Then .Font.Bold = True .HorizontalAlignment = xlRight ElseIf j1 = 2 Or j1 = 7 Then .HorizontalAlignment = xlLeft If R(c(1) - 1, j1) >= 1000 And R(c( 1) - 1, j1) < 10 ^ 9 Then .NumberFormat = "###,0.00 " If R(c(1) - 1, j1) < 1000 And R(c(1 ) - 1, j1) >= 10 ^ (-6) Then .NumberFormat = "##0.0 00000" End If End With With Cells(F + c(1) - 1, j1) .Borders(xlEdgeTop).LineStyle = xlConti nuous

Page 83: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

82

If j1 = 1 Or j1 = 2 Then If j1 = 1 Then .Characters(1, 1).Font.Name = "Sy mbol" .HorizontalAlignment = xlRight .VerticalAlignment = xlCenter Else .HorizontalAlignment = xlLeft If R(c(1) - 1, j1) >= 1000 And R( c(1) - 1, j1) < 10 ^ 9 Then .NumberFormat = "###,0. 00" If R(c(1) - 1, j1) < 1000 And R(c (1) - 1, j1) >= 10 ^ (-6) Then .NumberFormat = "##0 .000000" End If ElseIf j1 = 3 Or j1 = 6 Then .Characters(1, IIf(j1 = 3, 2, 8)).Fo nt.Bold = True .HorizontalAlignment = xlRight .VerticalAlignment = xlCenter ElseIf j1 = 4 Or j1 = 7 Then .HorizontalAlignment = xlLeft .NumberFormat = "0.0000" End If End With Next j1 If m(3) = 1 Then ActiveWindow.SelectedSheets. HPageBreaks.Add (Cells(F + c(1), 1)) End If ElseIf opcio = 7 Then 'CONSTRASTOS D'ESPECIFICACI Ó Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter For j1 = 1 To 3 Step 2 Range(Cells(F, j1), Cells(F + 1, j1 + 1)).Me rgeCells = True Next j1 For i1 = 1 To c(1) j1 = F + i1 - 1 If R(i1, 1) <> "" Then Range(Cells(j1, 1), C ells(j1, c(2))).Borders(xlEdgeTop).LineStyle = xlCo ntinuous If R(i1, 3) = "Durbin-Watson" Then Range(Cel ls(j1, 8), Cells(j1, 10)).MergeCells = True Range(Cells(j1, 1), Cells(j1, 2)).MergeCells = True With Range(Cells(j1, 3), Cells(j1, 4)) .HorizontalAlignment = xlLeft .MergeCells = True End With Next i1 Range(Cells(F, 5), Cells(F, 10)).Borders(xlBotto m).LineStyle = xlContinuous With Cells(F, 5).Characters(9, 1).Font .Name = "Symbol" .Bold = True End With With Cells(F + 1, 5).Characters(8, 1).Font .Name = "Symbol" .Bold = True End With With Cells(F + 1, 7).Characters(8, 1).Font .Name = "Symbol" .Bold = True End With Range(Cells(F, 3), Cells(F + c(1) - 1, 3)).Borde rs(xlLeft).LineStyle = xlContinuous For j1 = 5 To 8 Step 3 Range(Cells(F, j1), Cells(F, j1 + 2)).MergeC ells = True Range(Cells(F, j1), Cells(F + c(1) - 1, j1)) .Borders(xlLeft).LineStyle = xlDouble Range(Cells(F + 2, j1), Cells(F + c(1) - 1, j1)).NumberFormat = "###,0.000" Range(Cells(F + 2, j1 + 1), Cells(F + c(1) - 1, j1 + 1)).NumberFormat = "0" Range(Cells(F + 2, j1 + 2), Cells(F + c(1) - 1, j1 + 2)).NumberFormat = "0.0000" Next j1 If m(1) <> "" Then For i1 = 1 To UBound(m) With Range(Cells(F + c(1) - i1, 1), Cells (F + c(1) - i1, c(2))) If i1 = UBound(m) Then .Borders(xlEdgeT op).LineStyle = xlContinuous .Font.Bold = False .HorizontalAlignment = xlLeft .MergeCells = True .Value = m(UBound(m) - i1 + 1) End With Next i1 End If ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) ElseIf opcio = 9 Then 'HETEROSCEDASTICITAT Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter With Cells(F - 1, 1) With .Characters(m(2), 1).Font .Name = "Symbol" .Bold = True End With With .Characters(m(3), 1).Font .Name = "Symbol"

Page 84: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

83

.Bold = True End With If m(4) <> 0 Then With .Characters(m(4), 1).Font .Name = "Symbol" .Bold = True End With End If End With j1 = IIf(m(1) = "MV", IIf(m(6) = False, 2, 1), 1 ) With Range(Cells(F + 1, 1), Cells(F + c(1) - j1, 1)).Characters(1, 1).Font .Name = "Symbol" .Bold = True End With Range(Cells(F, 4), Cells(F + c(1) - 2, 4)).Numbe rFormat = "#####0.000" Range(Cells(F, 5), Cells(F + c(1) - 2, 5)).Numbe rFormat = "0.0000" Range(Cells(F + k + 2, 1), Cells(F + k + 2, c(2) )).Borders(xlEdgeTop).LineStyle = xlContinuous If Not m(6) Then For j1 = 1 To 5 With Cells(F + c(1) - 1, j1) .HorizontalAlignment = IIf(j1 = 1 Or j1 = 4, xlRight, IIf(j1 = 2 Or j1 = 5, xlLeft, xlCent er)) .Font.Bold = IIf(j1 = 1 Or j1 = 4, True , False) If m(1) = "MQG" Then If j1 = 3 Then .Characters(1, 4).Fon t.Bold = True Else Cells(F + c(1) - 1, j1).Borders(xlEd geTop).LineStyle = xlContinuous If j1 = 4 Then With .Characters(7, 1).Font .Name = "Symbol" .Bold = True End With End If End If End With Next j1 Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1, c(2))).VerticalAlignment = True End If For j1 = 2 To 3 For i1 = 2 To c(1) - IIf(m(1) = "MV", IIf(j1 = 2, 0, 1), IIf(j1 = 2, 0, 1)) With Cells(F + i1 - 1, j1) ' If Abs(R(i1, j1)) >= m1 And Abs(R(i1, j1)) <= m2 Then .NumberFormat = "#####0.000000" If Abs(R(i1, j1)) >= 1000 And Abs(R(i1 , j1)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j1)) < 1000 And Abs(R(i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000 " End With Next i1 Next j1 If m(5) = 1 Then ActiveWindow.SelectedSheets.HPa geBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 10 Then 'AUTOCORRELACIÓ Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter With Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).Characters(1, 1).Font .Name = "Symbol" .Bold = True End With Range(Cells(F, 4), Cells(F + c(1) - 1, 4)).Numbe rFormat = "#####0.000" Range(Cells(F, 5), Cells(F + c(1) - 1, 5)).Numbe rFormat = "0.0000" Range(Cells(F + k + 2, 1), Cells(F + k + 2, 5)). Borders(xlEdgeTop).LineStyle = xlContinuous Range(Cells(F + k + 2 + AUTO(1), 1), Cells(F + k + 2 + AUTO(1), 5)).Borders(xlEdgeTop).LineStyle = xlContinuous Range(Cells(F + k + 2 + AUTO(1), 2), Cells(F + c (1) - 1, 2)).HorizontalAlignment = xlLeft With Range(Cells(F + k + 2 + AUTO(1), 4), Cells( F + c(1) - 1, 4)) .Font.Bold = True .HorizontalAlignment = xlLeft End With Range(Cells(F + k + 2 + AUTO(1), 5), Cells(F + c (1) - 1, 5)).HorizontalAlignment = xlLeft For j1 = 2 To 3 For i1 = 2 To c(1) - 1 With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R(i1 , j1)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j1)) < 1000 And Abs(R(i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000 " End With Next i1 Next j1 If AUTO(2) = 1 Then i1 = 1 Else i1 = 2 Cells(F + c(1) - i1 - 1, 2).NumberFormat = "0.00 00" Cells(F + c(1) - i1, 2).NumberFormat = "0" If AUTO(2) <> 1 Then Cells(F + c(1) - 1, 2).Numb erFormat = "###,0" Cells(F + c(1) - i1, 5).NumberFormat = "###,0" If m(1) = 1 Then ActiveWindow.SelectedSheets.HPa geBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 11 Then 'ESTIMACIÓ VARIABLES INSTRUM ENTALS(MQ2E)

Page 85: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

84

Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter Range(Cells(F + 2, 1), Cells(F + k + 1, 1)).Char acters(1, 1).Font.Name = "Symbol" Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Bold = True Range(Cells(F + 2, 4), Cells(F + k + 1, 4)).Numb erFormat = "#####0.000" Range(Cells(F + 2, 5), Cells(F + k + 1, 5)).Numb erFormat = "0.0000" Range(Cells(F, 6), Cells(F + 1, 7)).MergeCells = True For j1 = 2 To 7 If j1 <> 4 And j1 <> 5 Then For i1 = 1 To k With Cells(F + i1 + 1, j1) If Abs(R(i1 + 2, j1)) >= 1000 And A bs(R(i1 + 2, j1)) < 10 ^ 9 Then .NumberFormat = "## #,0.00" If Abs(R(i1 + 2, j1)) < 1000 And Ab s(R(i1 + 2, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End With Next i1 End If Next j1 With Range(Cells(F + k + 2, 1), Cells(F + k + 2, c(2))).Borders(xlEdgeTop) .LineStyle = xlContinuous .Weight = xlMedium End With With Range(Cells(F + k + 2, 2), Cells(F + k + 2, 4)) .Characters(22, 1).Font.Subscript = True .Borders(xlEdgeBottom).LineStyle = xlContinuou s .HorizontalAlignment = xlCenter .MergeCells = True End With Range(Cells(F + k + 2, 1), Cells(F + k + 3, 7)). Font.Bold = True Range(Cells(F + k + 2, 1), Cells(F + k + 3, 1)). MergeCells = True With Range(Cells(F + k + 2, 5), Cells(F + k + 3, 7)) .Borders(xlEdgeBottom).LineStyle = xlContinuou s .HorizontalAlignment = xlCenter .MergeCells = True .VerticalAlignment = xlBottom End With Range(Cells(F + k + 3, 1), Cells(F + k + 3, 7)). Borders(xlEdgeBottom).LineStyle = xlContinuous With Range(Cells(F + k + 2, 2), Cells(F + c(1) - 1, 4)) .Borders(xlEdgeLeft).LineStyle = xlContinuous .Borders(xlEdgeRight).LineStyle = xlContinuous End With With Range(Cells(F + k + 4 + UBound(VI_X), 1), C ells(F + k + 4 + UBound(VI_X), 7)).Borders(xlEdgeTo p) .LineStyle = xlContinuous .Weight = xlMedium End With For j1 = F + k + 4 To F + k + 4 + UBound(VI_X) - 1 With Range(Cells(j1, 5), Cells(j1, 7)) .HorizontalAlignment = xlLeft .MergeCells = True End With With Range(Cells(j1, 2), Cells(j1, 2)) If Abs(R(j1 - F + 1, 2)) >= 1000 And Abs(R (j1 - F + 1, 2)) < 10 ^ 9 Then .NumberFormat = "### ,0.00" If Abs(R(j1 - F + 1, 2)) < 1000 And Abs(R( j1 - F + 1, 2)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End With Range(Cells(j1, 4), Cells(j1, 4)).NumberForm at = "0.0000" Next j1 i1 = F + k + 3 + UBound(VI_X) If i1 < F + c(1) - 1 Then Range(Cells(i1 + 1, 1), Cells(i1 + 1, 7)).Fon t.Bold = True Cells(i1 + 1, 5).Characters(7, 1).Font.Name = "Symbol" Cells(i1 + 1, 7).Characters(8, 1).Font.Name = "Symbol" Range(Cells(i1 + 1, 5), Cells(i1 + 1, 7)).Bor ders(xlEdgeBottom).LineStyle = xlContinuous With Range(Cells(i1 + 2, 2), Cells(i1 + 2, 4) ) .Characters(18, 1).Font.Subscript = True .Font.Bold = True .MergeCells = True .HorizontalAlignment = xlRight End With Cells(i1 + 2, 5).NumberFormat = "####,0.000" Cells(i1 + 2, 7).NumberFormat = "0.0000" End If If m(1, 1) = 1 Then ActiveWindow.SelectedSheets. HPageBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 12 Then 'ESTIMACIÓ "BOOTSTRAP" Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter With Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).Characters(1, 1).Font .Name = "Symbol" .Bold = True End With

Page 86: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

85

Range(Cells(F, 5), Cells(F + 1, 6)).MergeCells = True Range(Cells(F + 1, 4), Cells(F + c(1) - 1, 4)).N umberFormat = "0.000" Range(Cells(F + 1, 7), Cells(F + c(1) - 1, 7)).N umberFormat = "0.0000" For i1 = 2 To c(1) For j1 = 2 To c(2) If j1 <> 4 And j1 <> 7 Then With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R (i1, j1)) < 10 ^ 9 Then .NumberFormat = "###,0.00" If Abs(R(i1, j1)) < 1000 And Abs(R( i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000 000" End With End If Next j1 Next i1 ElseIf opcio = 121 Then 'ESTIMACIÓ "BOOTSTRAP" (2a. part) Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).F ont.Bold = True Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).N umberFormat = "###0.0%" For j1 = 2 To c(2) With Cells(F, j1) .Characters(1, 1).Font.Name = "Symbol" .Font.Bold = True End With For i1 = 2 To c(1) Cells(F + i1 - 1, j1).NumberFormat = "0. 0000" Next i1 Next j1 If m(1, 1) = 1 Then ActiveWindow.SelectedSheets. HPageBreaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 21 Or opcio = 22 Or opcio = 23 Then 'RESIDUS-PREDICCIONS , ATIPICITAT, RECURSIUS-CUSU MS Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Numbe rFormat = "@" If opcio = 21 Then If LLARG > 1 Then Range(Cells(F, 1), Cells(F, LLARG)).MergeCells = True Range(Cells(F, 4 + LLARG), Cells(F, 5 + LLARG )).MergeCells = True ElseIf opcio = 22 Then If Left(TITOL, 1) = "I" Then With Range(Cells(F, 1 + LLARG), Cells(F, c (2))).Characters(1, 1).Font .Name = "Symbol" .Bold = True End With End If Range(Cells(F, 1), Cells(F, LLARG)).MergeCell s = True Else Range(Cells(F, 4), Cells(F, 5)).MergeCells = True Range(Cells(F, 7), Cells(F, 8)).MergeCells = True End If k1 = IIf(opcio <> 23, 0, IIf(Right(TITOL, 1) = " A", k, 0)) For i1 = 1 + k1 To c(1) - 2 If opcio <> 23 Then Range(Cells(F + i1 + 1, 1), Cells(F + i1 + 1, LLARG)).MergeCells = True For j1 = 1 + IIf(opcio = 23, 1, LLARG) To c( 2) With Cells(F + i1 + 1, j1) If Abs(R(i1 + 2, j1)) >= 1000 And Abs( R(i1 + 2, j1)) < 10 ^ 9 Then .NumberFormat = "###,0 .00" If Abs(R(i1 + 2, j1)) < 1000 And Abs(R (i1 + 2, j1)) >= 10 ^ (-6) Then .NumberFormat = "## 0.0000" If opcio = 22 Then If Abs(R(i1 + 2, j1)) > m(j1) Then With .Font .Bold = True .Italic = True End With End If End If End With Next j1 Next i1 ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) End If F = F + c(1) + 2 Sheets(FULL).Activate End Sub Private Sub M1_ESCRIPTURA_1(O As Integer, aux, aux1 , TITOL As String) '''''''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A L'ESCRIPTURA DE MATRIUS' '''''''''''''''''''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, j1 As Integer, j2 As Integer, j22 As Integer Dim dim1 As Integer, dim2 As Integer, maxim2 As Int eger, mat(1 To 1), resta2 As Integer

Page 87: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

86

dim1 = UBound(aux, 1) dim2 = IIf(dim1 <= 9, dim1, 9) maxim2 = IIf(dim1 <= 9, 1, Int(dim1 / 9)) resta2 = IIf(dim1 <= 9, 0, dim1 - (maxim2 * 9)) If resta2 <> 0 Then maxim2 = maxim2 + 1 For j2 = 1 To maxim2 ReDim R(1 To dim1 + 1, 1 To IIf(j2 < maxim2, di m2, IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2 ))) + 1) If O = 63 Or O = 64 Then R(1, 1) = "Valor Propi o" For j22 = 1 To IIf(j2 < maxim2, dim2, IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) i2 = j22 + ((j2 - 1) * 9) + IIf(O = 61 Or O = 64, IC, 0) R(1, j22 + 1) = IIf(O <> 61, "b" & i2 & "(" & LVAR(i2, 2) & ")", LVAR(i2, 2)) Next j22 For i1 = 1 To dim1 If O = 63 Or O = 64 Then R(i1 + 1, 1) = aux1(i1) Else R(i1 + 1, 1) = IIf(O <> 61, "b" & i1 & " (" & LVAR(i1, 2) & ")", LVAR(i1 + IC, 2)) End If For j22 = 1 To IIf(j2 < maxim2, dim2, IIf(j 2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) R(i1 + 1, j22 + 1) = aux(i1, j22 + ((j2 - 1) * 9)) Next j22 Next i1 If O = 3 Or O = 8 Or O = 11 Then If dim1 <= 9 Then mat(1) = 1 ElseIf dim1 <= 18 Then mat(1) = IIf(j2 = 2, 1, 0) ElseIf dim1 <= 27 Then mat(1) = IIf(j2 = 1 Or j2 = 3, 1, 0) ElseIf dim1 <= 33 Then mat(1) = IIf(j2 = 2 Or j2 = 4, 1, 0) Else mat(1) = 1 End If Else If dim1 <= 15 Then If maxim2 = 1 Then mat(1) = IIf(O = 63, 1 , 0) Else mat(1) = IIf(j2 = 1, 0, IIf(O = 61, 0, 1) ) ElseIf dim1 <= 21 Then If maxim2 = 2 Then mat(1) = IIf(j2 = 2, 1 , 0) Else mat(1) = IIf(j2 = 3, 1, 0) ElseIf dim1 <= 33 Then If maxim2 <= 3 Then mat(1) = IIf(j2 <> 1, 1, 0) Else mat(1) = IIf(j2 = 2 Or j2 = 4, 1, 0) Else mat(1) = 1 End If End If Call M1_ESCRIPTURA(0, TITOL & IIf(j2 = 1, "", " (cont.)"), mat) Next j2 End Sub Private Sub M1_GRAFICS(opcio As Integer) '''''''''''''''''''''''''' 'CONSTRUCCIÓ DELS GRAFICS' '''''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, ncells As Integer , signe If opcio = 1 Then ReDim a1(1 To 6, 1 To 8), tit(1 To 6) As String For i1 = 1 To 6 If i1 = 1 Then tit(i1) = "Normalidad residuo s" If i1 = 2 Then tit(i1) = "Residuos MCO" If i1 = 3 Then tit(i1) = "Realización vs. Pr edicción" If i1 = 4 Then tit(i1) = "Simulación" If i1 = 5 Then tit(i1) = "Residuos MCO vs. " & UCase(LVAR(k + 1, 2)) If i1 = 6 Then tit(i1) = "Residuos MCO vs. P redicciones" Call M1_GRAFICS_1(a1, i1, 1) Next i1 ncells = 73 End If If opcio = 2 Then ReDim a1(1 To 6, 1 To 8), tit(1 To 6) As String For i1 = 1 To 6 If i1 = 1 Then tit(i1) = "Residuos estandari zados" If i1 = 2 Then tit(i1) = "Residuos 'studenti zados'" If i1 = 3 Then tit(i1) = "Residuos 'studenti zados' (omisión)" If i1 = 4 Then tit(i1) = "Leverage" If i1 = 5 Then tit(i1) = "Distancia de Cook" If i1 = 6 Then tit(i1) = "DFFITS" Call M1_GRAFICS_1(a1, i1, 2) Next i1 ncells = 73

Page 88: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

87

End If If opcio = 3 Then ReDim a1(1 To 3, 1 To 8), tit(1 To 3) As String For i1 = 1 To 3 If i1 = 1 Then tit(i1) = "Residuos recursivo s" If i1 = 2 Then tit(i1) = "CUSUM " & "(sig.=" & Format(SIG, "0.00") & ")" If i1 = 3 Then tit(i1) = "CUSUMSQ " & "(sig. =" & Format(SIG, "0.00") & ")" Call M1_GRAFICS_1(a1, i1, 3) Next i1 ncells = 48 End If Sheets(FULL_R).Activate With Range(Cells(F - 2, 1), Cells(F - 2 + ncells, 1 0)) .Interior.ColorIndex = 2 .ColumnWidth = 9.5 .RowHeight = 11 End With For i1 = 1 To IIf(opcio <> 3, 6, 3) '''''''''''''''''''' 'Creació del gràfic' '''''''''''''''''''' Charts.Add With ActiveChart .ChartType = xlXYScatter .SeriesCollection.NewSeries If opcio = 1 Then '''''''''''''''''''''''''''''''''''''''''' ''''' 'Gràfics corresponents a residus i predicc ions' '''''''''''''''''''''''''''''''''''''''''' ''''' With .SeriesCollection(1) .Border.ColorIndex = 5 .Border.LineStyle = xlContinuous .Border.Weight = xlMedium .MarkerBackgroundColorIndex = 5 .MarkerForegroundColorIndex = 2 .MarkerSize = 5 .MarkerStyle = 2 If i1 = 1 Then .Values = RG.Columns(5) .XValues = RG.Columns(6) ElseIf i1 = 2 Then .Values = RG.Columns(2) .XValues = RG.Columns(1) ElseIf i1 = 3 Then .Border.LineStyle = xlNone .Values = RG.Columns(3) .XValues = RG.Columns(4) ElseIf i1 = 4 Then .Name = "Observación" .Values = RG.Columns(3) .XValues = RG.Columns(1) ElseIf i1 = 5 Then .Border.LineStyle = xlNone .Values = RG.Columns(2) .XValues = RG.Columns(3) ElseIf i1 = 6 Then .Border.LineStyle = xlNone .Values = RG.Columns(2) .XValues = RG.Columns(4) End If End With '''''''''''''''''''''''''''''''''''''''''' ''''''''''' 'Normalitat(1),Realització-Predicció(3),Si mulació(4)' '''''''''''''''''''''''''''''''''''''''''' ''''''''''' If i1 = 1 Or i1 = 3 Or i1 = 4 Then .SeriesCollection.NewSeries With .SeriesCollection(2) If i1 = 1 Or i1 = 3 Then .Border.ColorIndex = 1 .Border.Weight = xlMedium .MarkerStyle = xlNone .Values = IIf(i1 = 1, RG.Columns(7 ), Array(a1(i1, 1), a1(i1, 2))) .XValues = IIf(i1 = 1, RG.Columns( 6), Array(a1(i1, 1), a1(i1, 2)))

Page 89: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

88

ElseIf i1 = 4 Then .Border.ColorIndex = 3 .Border.Weight = xlMedium .MarkerBackgroundColorIndex = 3 .MarkerForegroundColorIndex = 3 .MarkerSize = 4 .MarkerStyle = 2 .Name = "Predicción" .Values = RG.Columns(4) .XValues = RG.Columns(1) End If End With End If If i1 = 1 Then For i2 = ActiveChart.SeriesCollection.C ount To 3 Step -1 ActiveChart.SeriesCollection(i2).De lete Next i2 End If ElseIf opcio = 2 Then '''''''''''''''''''''''''''''''''''''''''' ''''''' 'Gràfics corresponents a atipicitat i infl uència' '''''''''''''''''''''''''''''''''''''''''' ''''''' With .SeriesCollection(1) .Border.ColorIndex = 3 .Border.LineStyle = xlContinuous .Border.Weight = xlMedium .MarkerBackgroundColorIndex = 3 .MarkerForegroundColorIndex = 2 .MarkerSize = 5 .MarkerStyle = 2 .Values = RG.Columns(i1 + 1) .XValues = RG.Columns(1) End With '''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' 'Res. estand.(1),Res. stud.(2),res estud.c orr.(3),leverage(4),DFFITS(6)' '''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''' If i1 <> 5 Then For i2 = 2 To IIf(i1 = 4, 2, 3) .SeriesCollection.NewSeries With .SeriesCollection(i2) .Border.ColorIndex = 1 .Border.LineStyle = xlDashDotDot .Border.Weight = xlThin .MarkerStyle = xlNone signe = IIf(i2 = 2, 1, -1) If i1 = 1 Then .Values = Array(signe * 1.6448 53, signe * 1.644853) ElseIf i1 = 2 Then .Values = Array(signe * Applic ation.TInv(0.05, N - k), _ signe * Applic ation.TInv(0.05, N - k)) ElseIf i1 = 3 Then .Values = Array(signe * Applic ation.TInv(0.05, N - k - 1), _ signe * Applic ation.TInv(0.05, N - k - 1)) ElseIf i1 = 4 Then .Values = Array(2 * k / N, 2 * k / N) ElseIf i1 = 6 Then .Values = Array(signe * 2 * Sq r(k / N), signe * 2 * Sqr(k / N)) End If .XValues = Array(a1(i1, 1), a1(i1 , 2)) End With Next i2 If i1 = 1 Then For i2 = ActiveChart.SeriesCollectio n.Count To 4 Step -1 ActiveChart.SeriesCollection(i2) .Delete Next i2 End If End If Else '''''''''''''''''''''''''''''''''''''''''' ' 'Gràfics corresponents a residus recursius ' '''''''''''''''''''''''''''''''''''''''''' ' With .SeriesCollection(1) .Border.ColorIndex = 1

Page 90: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

89

.Border.LineStyle = xlContinuous .Border.Weight = xlMedium .MarkerBackgroundColorIndex = 1 .MarkerForegroundColorIndex = 2 .MarkerSize = 5 .MarkerStyle = 2 .Values = RG.Columns(IIf(i1 = 1, 2, IIf( i1 = 2, 3, 6))) .XValues = RG.Columns(1) End With If i1 = 1 Then For i2 = ActiveChart.SeriesCollection.C ount To 2 Step -1 ActiveChart.SeriesCollection(i2).De lete Next i2 End If ''''''''''''''''''''' 'CUSUM(2),CUSUMSQ(3)' ''''''''''''''''''''' If i1 = 2 Or i1 = 3 Then For i2 = 2 To 3 .SeriesCollection.NewSeries With .SeriesCollection(i2) .Border.ColorIndex = 1 .Border.LineStyle = xlContinuous .Border.Weight = xlMedium .MarkerStyle = xlNone .Values = RG.Columns(IIf(i1 = 2, i2 + 2, i2 + 5)) .XValues = RG.Columns(1) End With Next i2 End If End If ''''''''''''''''''''''''''''''''''''''' 'Característiques de l'eix horitzontal' ''''''''''''''''''''''''''''''''''''''' With .Axes(xlCategory) .HasMajorGridlines = False .HasMinorGridlines = False .MinimumScale = a1(i1, 1) .MaximumScale = a1(i1, 2) .MinorUnit = a1(i1, 3) .MajorUnit = a1(i1, 4) .TickLabels.AutoScaleFont = False .TickLabels.Font.Size = 8 .TickLabels.NumberFormat = "0" If opcio = 1 And (i1 = 1 Or i1 = 3 Or i1 = 5 Or i1 = 6) Then .TickLabels.NumberFormat = "@" .CrossesAt = a1(i1, 1) End With '''''''''''''''''''''''''''''''''''' 'Característiques de l'eix vertical' '''''''''''''''''''''''''''''''''''' With .Axes(xlValue) .HasMajorGridlines = False .HasMinorGridlines = False .MinimumScale = a1(i1, 5) .MaximumScale = a1(i1, 6) .MinorUnit = a1(i1, 7) .MajorUnit = a1(i1, 8) .TickLabels.AutoScaleFont = False .TickLabels.Font.Size = 8 .TickLabels.NumberFormat = "@" If opcio = 1 And (i1 = 3 Or i1 = 4) Then .C rossesAt = a1(i1, 5) End With ''''''''''''''''''''''''''''''''''''''' 'Característiques de l'area del gràfic' ''''''''''''''''''''''''''''''''''''''' With .PlotArea .Border.Weight = xlThin .Border.LineStyle = xlNone .Interior.ColorIndex = 2 .Interior.PatternColorIndex = 1 .Interior.Pattern = xlSolid End With

Page 91: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

90

'''''''''''''''''' 'Llegenda i títol' '''''''''''''''''' .HasLegend = False .HasTitle = True .ChartTitle.AutoScaleFont = False .ChartTitle.Characters.Text = tit(i1) .ChartTitle.Font.Size = 9 .ChartTitle.Font.Bold = True If opcio = 1 And i1 = 4 Then .HasLegend = True .Legend.AutoScaleFont = False .Legend.Border.LineStyle = xlNone .Legend.Font.Size = 8 .Legend.Position = xlLegendPositionBottom End If ''''''''''''''''''''''''' 'Localització del gràfic' ''''''''''''''''''''''''' .Location Where:=xlLocationAsObject, Name:=FU LL_R End With ''''''''''''''''''''''''''''''' 'Amplada i alçada dels gràfics' ''''''''''''''''''''''''''''''' With Worksheets(FULL_R) .ChartObjects(1).Width = 265 .ChartObjects(1).Height = 245 End With ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''' 'Reconversió dels gràfics en imatges i eliminac ió dels gràfics' ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''' ActiveSheet.ChartObjects(1).CopyPicture ActiveWindow.Visible = False Cells(IIf(i1 >= 5, F + 49, IIf(i1 >= 3, F + 24, F - 1)), IIf(i1 = 1 Or i1 = 3 Or i1 = 5, 1, 6)).Se lect ActiveSheet.Paste Worksheets(FULL_R).ChartObjects(1).Delete Next i1 ActiveWindow.SelectedSheets.HPageBreaks.Add (Cells( F + ncells - 1, 1)) F = F + ncells Cells(1, 1).Select RG.Clear Sheets(FULL).Activate End Sub Private Sub M1_GRAFICS_1(a, i As Integer, opcio) '''''''''''''''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A CALCULAR ELS EIXOS DELS GRAFICS' '''''''''''''''''''''''''''''''''''''''''''''''' Dim aux As Double If opcio = 1 Then If i = 1 Then 'Normalitat Residus aux = Application.max(Abs(RG.Columns(6).Rows( 1)), Abs(RG.Columns(6).Rows(N))) Call M1_GRAFICS_2(aux, a(i, 2), 2) a(i, 1) = -a(i, 2) a(i, 3) = (2 * a(i, 2)) / 10 a(i, 4) = a(i, 3) aux = Application.max(Abs(RG.Columns(5).Rows( 1)), Abs(RG.Columns(5).Rows(N)), Abs(RG.Columns(7). Rows(1)), _ Abs(RG.Columns(7).R ows(N))) Call M1_GRAFICS_2(aux, a(i, 6), 2) a(i, 5) = -a(i, 6) a(i, 7) = (2 * a(i, 6)) / 10 a(i, 8) = a(i, 7) ElseIf i = 2 Then 'Residus MQO" a(i, 1) = 0 a(i, 2) = N a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) aux = Application.max(Abs(Application.min(RG. Columns(2))), Abs(Application.max(RG.Columns(2))))

Page 92: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

91

Call M1_GRAFICS_2(aux, a(i, 6), 2) a(i, 5) = -a(i, 6) a(i, 7) = (2 * a(i, 6)) / 10 a(i, 8) = a(i, 7) ElseIf i = 3 Then 'Realització vs. Predicció aux = Application.min(Application.min(RG.Colu mns(3)), Application.min(RG.Columns(4))) Call M1_GRAFICS_2(aux, a(i, 1), 1) aux = Application.max(Application.max(RG.Colu mns(3)), Application.max(RG.Columns(4))) Call M1_GRAFICS_2(aux, a(i, 2), 2) a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) a(i, 5) = a(i, 1) a(i, 6) = a(i, 2) a(i, 7) = a(i, 3) a(i, 8) = a(i, 4) ElseIf i = 4 Then 'Simulació a(i, 1) = a(2, 1) a(i, 2) = a(2, 2) a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) a(i, 5) = a(3, 1) a(i, 6) = a(3, 2) a(i, 7) = a(3, 7) a(i, 8) = a(3, 8) ElseIf i = 5 Then 'Residus MCO vs. " variable en dògena aux = Application.min(RG.Columns(3)) Call M1_GRAFICS_2(aux, a(i, 1), 1) aux = Application.max(RG.Columns(3)) Call M1_GRAFICS_2(aux, a(i, 2), 2) a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) a(i, 5) = a(2, 5) a(i, 6) = a(2, 6) a(i, 7) = a(2, 7) a(i, 8) = a(2, 8) ElseIf i = 6 Then 'Residus MQO vs. Prediccions aux = Application.min(RG.Columns(4)) Call M1_GRAFICS_2(aux, a(i, 1), 1) aux = Application.max(RG.Columns(4)) Call M1_GRAFICS_2(aux, a(i, 2), 2) a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) a(i, 5) = a(2, 5) a(i, 6) = a(2, 6) a(i, 7) = a(2, 7) a(i, 8) = a(2, 8) End If End If If opcio = 2 Then 'Atipicitat a(i, 1) = 0 a(i, 2) = N a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) If i <> 4 And i <> 5 Then aux = Application.max(Abs(Application.min(RG. Columns(i + 1))), Abs(Application.max(RG.Columns(i + 1)))) Call M1_GRAFICS_2(aux, a(i, 6), 2) a(i, 5) = -a(i, 6) Else a(i, 5) = 0 aux = Application.max(RG.Columns(i + 1)) Call M1_GRAFICS_2(aux, a(i, 6), 2) End If a(i, 7) = (2 * a(i, 6)) / 10 a(i, 8) = a(i, 7) End If If opcio = 3 Then 'Residus recursius a(i, 1) = 0 a(i, 2) = N a(i, 3) = (a(i, 2) - a(i, 1)) / 10 a(i, 4) = a(i, 3) If i = 1 Then aux = Application.max(Abs(Application.min(RG. Columns(i + 1))), Abs(Application.max(RG.Columns(i + 1)))) ElseIf i = 2 Then aux = Application.max(Abs(Application.min(RG. Columns(i + 2))), Abs(Application.max(RG.Columns(i + 2))), _ Abs(Application.min(RG. Columns(i + 3))), Abs(Application.max(RG.Columns(i + 3))), _ Abs(Application.min(RG. Columns(i + 4))), Abs(Application.max(RG.Columns(i + 5)))) ElseIf i = 3 Then aux = Application.max(Abs(Application.min(RG. Columns(i + 3))), Abs(Application.max(RG.Columns(i + 3))), _ Abs(Application.min(RG. Columns(i + 4))), Abs(Application.max(RG.Columns(i + 4))), _ Abs(Application.min(RG. Columns(i + 5))), Abs(Application.max(RG.Columns(i + 5)))) End If Call M1_GRAFICS_2(aux, a(i, 6), 2) a(i, 5) = -a(i, 6)

Page 93: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

92

a(i, 7) = (2 * a(i, 6)) / 10 a(i, 8) = a(i, 7) End If End Sub Private Sub M1_GRAFICS_2(v, v1, opcio As Integer) Dim i1 As Integer If (v - Int(v)) <> 0 Then If v < 99 Then For i1 = 0 To 10 If (v - Int(v)) > 10 ^ (-i1) Then Exit Fo r Next i1 If v < 1 Then i1 = i1 + 1 v1 = Round(v - Int(v), i1) If opcio = 1 Then If (v - Int(v) - v1) < 0 Then v1 = Int(v) + (v1 - 10 ^ (-i1)) Else v1 = Int(v) + v1 Else If (v - Int(v) - v1) > 0 Then v1 = Int(v) + (v1 + 10 ^ (-i1)) Else v1 = Int(v) + v1 End If Else v1 = Round(v) End If Else v1 = v End If End Sub

Page 94: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

93

Attribute VB_Name = "M2_DatosPanel1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVISEXOGENES As Boolean Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Long, nobs ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then NY = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable endógena.", vbCritical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VX(1 To i2) VX(i2) = i1 NX = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar al menos una variable e xógena.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If NY = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y exógena.", vbCritical, TITOL Exit Sub End If Next i1 If cros.Value = "" Then ERR_LEC = True Me.Hide MsgBox "El número, N, de observaciones individua les está en blanco.", vbCritical, TITOL Exit Sub End If If Not IsNumeric(cros.Value) Or Val(cros.Value) = 0 Then ERR_LEC = True Me.Hide MsgBox "El número, N, de observaciones individua les es incorrecto.", vbCritical, TITOL Exit Sub End If If time.Value = "" Then ERR_LEC = True Me.Hide MsgBox "El número, T, de observaciones temporale s está en blanco.", vbCritical, TITOL Exit Sub End If If Not IsNumeric(time.Value) Or Val(time.Value) = 0 Then ERR_LEC = True Me.Hide MsgBox "El número, T, de observaciones temporale s es incorrecto.", vbCritical, TITOL Exit Sub End If N = Val(cros.Value) T = Val(time.Value) NT = R_XY.Rows.Count ERR_LEC = False If NT <> N * T Then ERR_LEC = True Me.Hide

Page 95: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

94

MsgBox "Ha indicado N=" & N & " T=" & T & Chr(10 ) & ". Estos valores no coinciden con el rango de l as variables.", vbCritical, TITOL Exit Sub End If If Application.Count(R_XY.Columns(NY)) <> NT Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(NY, 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If Application.Count(R_XY.Columns(VX(i1))) <> NT Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(V X(i1), 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If Next i1 If Constante.Value = True Then IC = 1 Else IC = 0 k = IC + NX ReDim G2SWEEP(1 To k + 1, 1 To k + 1), XY(1 To NT, 1 To k + 1), PES(1 To NT) NTPESM = 1 NTPES = N For i3 = 1 To NT PES(i3) = 1 If IC = 1 Then XY(i3, 1) = 1 For i1 = 1 To NX XY(i3, IC + i1) = R_XY.Rows(i3).Columns(VX( i1)) Next i1 XY(i3, k + 1) = R_XY.Rows(i3).Columns(NY) For i1 = 1 To k + 1 For i2 = i1 To k + 1 G2SWEEP(i1, i2) = G2SWEEP(i1, i2) + (XY (i3, i1) * XY(i3, i2) * PES(i3)) Next i2 Next i1 Next i3 For i1 = 1 To k + 1 For i2 = i1 + 1 To k + 1 G2SWEEP(i2, i1) = G2SWEEP(i1, i2) Next i2 Next i1 ERROR_COMBINACIO = False Call C_G2SWEEP(0, IC, G2SWEEP, NT, k + 1, 0.0000000 1, ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide MsgBox "El modelo no es de rango completo.", vbC ritical, TITOL Exit Sub End If If IC = 1 Then LVAR(1, 2) = "Const." For i1 = 1 To NX LVAR(IC + i1, 2) = LVAR(VX(i1), 1) Next i1 LVAR(k + 1, 2) = LVAR(NY, 1) Call ANALISIS(1) End Sub Private Sub Cancelar_Click() SORTIR = True Unload Me End Sub Private Sub ANALISIS(opcio As Integer) 'DATOS DE P ANEL-I Dim i1 As Integer, j1 As Integer '''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul '''''''''''''''''''''''''''''''' ReDim OPT(1 To 15, 1 To 2) For i1 = 1 To 15 For j1 = 1 To 2 OPT(i1, j1) = False Next j1

Page 96: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

95

Next i1 OPT(1, 1) = True OPT(1, 2) = True OPT(2, 1) = True OPT(3, 1) = True If i_fijos Then OPT(4, 1) = True OPT(4, 2) = True End If If t_fijos Then OPT(8, 1) = True OPT(8, 2) = True End If If it_fijos Then OPT(4, 1) = True OPT(8, 1) = True OPT(12, 1) = True OPT(12, 2) = True End If If (i_fijos Or t_fijos Or it_fijos) Then If Fijos_impresion Then If N + T <= 200 Then IMP_F = True Else IMP_F = False Else IMP_F = False End If Else IMP_F = False End If If i_alea Then OPT(4, 1) = True If Nerlove Then OPT(5, 1) = True OPT(5, 2) = True End If If Swamy Then OPT(6, 1) = True OPT(6, 2) = True End If If Fuller Then OPT(7, 1) = True OPT(7, 2) = True End If If Not Nerlove And Not Swamy And Not Fuller Then OPT(7, 1) = True OPT(7, 2) = True End If End If If t_alea Then OPT(8, 1) = True If Nerlove Then OPT(9, 1) = True OPT(9, 2) = True End If If Swamy Then OPT(10, 1) = True OPT(10, 2) = True End If If Fuller Then OPT(11, 1) = True OPT(11, 2) = True End If If Not Nerlove And Not Swamy And Not Fuller Then OPT(11, 1) = True OPT(11, 2) = True End If End If If it_alea Then OPT(4, 1) = True OPT(8, 1) = True OPT(12, 1) = True If Nerlove Then OPT(13, 1) = True OPT(13, 2) = True End If If Swamy Then OPT(14, 1) = True OPT(14, 2) = True End If If Fuller Then OPT(15, 1) = True OPT(15, 2) = True End If If Not Nerlove And Not Swamy And Not Fuller Then

Page 97: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

96

OPT(15, 1) = True OPT(15, 2) = True End If End If Me.Hide End Sub Private Sub EXOGENES(opcio As Integer) Dim i1 As Integer AVISEXOGENES = False For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then AVISEXOGENES = True Exit For End If Next i1 If AVISEXOGENES Then For Each CTL In Me.Controls CTL.Enabled = True Next CTL Else For Each CTL In Me.Controls CTL.Enabled = False Next CTL Label1.Enabled = True Label2.Enabled = True ys.Enabled = True xs.Enabled = True End If End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() Label2.Enabled = True xs.Enabled = True End Sub Private Sub xs_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call EXOGENES(1) End Sub

Page 98: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

97

Attribute VB_Name = "M2" Option Explicit Public IMP_F As Boolean, MMCO() As Double, MU() As Double, NT As Long, SSE(1 To 15) As Double, _ SST(1 To 15) As Double, S2_E(1 To 3) As Doub le, S2_I(1 To 3) As Double, S2_T(1 To 3) As Double, _ T As Integer, XY_I() As Double, XY_T() As Do uble Sub M2_(opcio As Integer) '''''''''''''''''' 'DATOS DE PANEL-I' '''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' ''''''''''''''''''''''''''''''''''''''''''''' 'opt(1,1) sin efectos ' 'opt(2,1) entre grupos i ' 'opt(3,1) entre grupos t ' 'opt(4,1) efectos fijos i ' 'opt(5,1) efectos aleatorios i (Nerlove) ' 'opt(6,1) efectos aleatorios i (Swammy) ' 'opt(7,1) efectos aleatorios i (Fuller) ' 'opt(8,1) efectos fijos t ' 'opt(9,1) efectos aleatorios t (Nerlove) ' 'opt(10,1) efectos aleatorios t (Swammy) ' 'opt(11,1) efectos aleatorios t (Fuller) ' 'opt(12,1) efectos fijos i,t ' 'opt(13,1) efectos aleatorios i,t (Nerlove)' 'opt(14,1) efectos aleatorios i,t (Swammy) ' 'opt(15,1) efectos aleatorios i,t (Fuller) ' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria2: Mod elos de Datos de panel-I)' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 TITOL = "MicroEconometría: Modelos de Datos de Pane l-I" h = Application.min(110, 11 * R_XY.Columns.Count) With M2_DatosPanel1 .ys.Move Height:=h, Left:=65, Top:=30, Width:=90 .ys.List = v .xs.Move Height:=h, Left:=160, Top:=30, Width:=90 .xs.List = v End With ERR_LEC = True SORTIR = False Do While ERR_LEC = True M2_DatosPanel1.Show If SORTIR Then ERR_LEC = False Loop Unload M2_DatosPanel1 If SORTIR Then Exit Sub Call M2_01_CALCULS_PRELIMINARS(1) Call M2_02_CALCULS_MODELS(1) INOU = INOU + 1 End Sub Private Sub M2_01_CALCULS_PRELIMINARS(opcio As Inte ger) Dim i1 As Long, i2 As Long, i3 As Long, j1 As Integ er, k1 As Integer ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' 'Calcula e'e i guarda la inversa en el model sense efectes' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' ReDim MMCO(1 To k + 1, 1 To k + 1, 1 To 4), XY_I(1 To N, 1 To k + 1), _ XY_T(1 To T, 1 To k + 1) SST(1) = IIf(IC = 1, Application.DevSq(R_XY.Columns (NY)), Application.SumSq(R_XY.Columns(NY))) SSE(1) = G2SWEEP(k + 1, k + 1)

Page 99: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

98

For k1 = 1 To k + 1 For j1 = 1 To k + 1 MMCO(k1, j1, 1) = G2SWEEP(k1, j1) Next j1 Next k1 ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''' 'Genera les variables dels estimadors entre-grups l ongitudinal i temporal' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''' For i1 = 1 To N For k1 = 1 To T i3 = T * (i1 - 1) + k1 For j1 = 1 To k + 1 XY_I(i1, j1) = XY_I(i1, j1) + (XY(i3, j 1) / T) Next j1 Next k1 Next i1 For k1 = 1 To T For i2 = 1 To N i3 = T * (i2 - 1) + k1 For j1 = 1 To k + 1 XY_T(k1, j1) = XY_T(k1, j1) + (XY(i3, j 1) / N) Next j1 Next i2 Next k1 End Sub Private Sub M2_02_CALCULS_MODELS(opcio As Integer) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' 'i= 1 => MODELO SIN EFECTOS ' 'i= 2 => MODELO ENTRE-GRUPOS LONGITUDINAL ' 'i= 3 => MODELO ENTRE-GRUPOS TEMPORAL ' 'i= 4 => MODELO EFECTOS FIJOS LONGITUDINAL ' 'i= 5 => MODELO EFECTOS ALEATORIOS LONGITUDINAL (NE RLOVE) ' 'i= 6 => MODELO EFECTOS ALEATORIOS LONGITUDINAL (SW AMY-ARORA) ' 'i= 7 => MODELO EFECTOS ALEATORIOS LONGITUDINAL (FU LLER-BATESSE)' 'i= 8 => MODELO EFECTOS FIJOS TEMPORAL ' 'i= 9 => MODELO EFECTOS ALEATORIOS TEMPORAL (NERLOV E) ' 'i=10 => MODELO EFECTOS ALEATORIOS TEMPORAL (SWAMY- ARORA) ' 'i=11 => MODELO EFECTOS ALEATORIOS TEMPORAL (FULLER -BATESSE) ' 'i=12 => MODELO EFECTOS FIJOS CONJUNTOS ' 'i=13 => MODELO EFECTOS ALEATORIOS CONJUNTOS (NERLO VE) ' 'i=14 => MODELO EFECTOS ALEATORIOS CONJUNTOS (SWAMY-ARORA) ' 'i=15 => MODELO EFECTOS ALEATORIOS CONJUNTOS (FULLE R-BATESSE) ' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' Dim a(1 To 3, 1 To 2) As Double, aux1() As Double, aux2() As Double, avis As Boolean, _ i As Integer, i1 As Long, i2 As Long, i3 As Lon g, i4 As Long, j1 As Long, k1 As Long, _ maux() As Double, ncols As Long, obs As Long, t itol1 As String, traza As Double ReDim GL(1 To 15), v_est(1 To 4) As String, mean(k + 1) As Double v_est(1) = "(Nerlove, 1971) " v_est(2) = "(Swamy-Arora, 1972) " v_est(3) = "(Fuller-Batesse, 1973)" v_est(4) = "(Fuller-Batesse, 1974)" mean(1) = 1 For j1 = 1 To NX mean(j1 + IC) = Application.Average(R_XY.Column s(VX(NX))) Next j1 mean(k + 1) = Application.Average(R_XY.Columns(NY)) For i = 1 To 15 avis = False If Not OPT(i, 1) Then GoTo SALTA2 obs = NT If i = 2 Then obs = N If i = 3 Then obs = T If (i <> 4 And i <> 8 And i <> 12) Then GL(i) = obs - k ncols = k + 1 ElseIf i = 4 Then GL(i) = (N * (T - 1)) - (k - IC) If Not IMP_F Then ncols = k + 1 - IC Else n cols = (N - IC) + k + 1 ElseIf i = 8 Then GL(i) = (T * (N - 1)) - (k - IC) If Not IMP_F Then ncols = k + 1 - IC Else n cols = (T - IC) + k + 1 Else GL(i) = ((N - 1) * (T - 1)) - (k - IC) If Not IMP_F Then ncols = k + 1 - IC Else n cols = (N - IC) + (T - 1) + k + 1 End If

Page 100: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

99

ReDim m(1 To ncols, 1 To ncols) As Double, xy_( 1 To obs, 1 To ncols) As Double If i = 1 Then titol1 = "MODELO SIN EFECTOS" For i1 = 1 To ncols For j1 = 1 To ncols m(i1, j1) = MMCO(i1, j1, 1) Next j1 Next i1 GoTo salta ElseIf (i = 2 Or i = 3) Then titol1 = "" For i1 = 1 To IIf(i = 2, N, T) For j1 = 1 To ncols If i = 2 Then xy_(i1, j1) = XY_I(i1, j1) Else xy_(i1, j1) = XY_T(i1, j1) Next j1 Next i1 ElseIf (i = 4 Or i = 8) Then If i = 4 Then titol1 = "MODELO DE EFECTOS FI JOS LONGITUDINALES" If i = 8 Then titol1 = "MODELO DE EFECTOS FI JOS TEMPORALES" If Not IMP_F Then For i1 = 1 To IIf(i = 4, N, T) For i2 = 1 To IIf(i = 4, T, N) If i = 4 Then i3 = T * (i1 - 1) + i2 Else i3 = T * (i2 - 1) + i1 For j1 = 1 To ncols If i = 4 Then xy_(i3, j1) = X Y(i3, j1 + IC) - XY_I(i1, j1 + IC) If i = 8 Then xy_(i3, j1) = X Y(i3, j1 + IC) - XY_T(i1, j1 + IC) Next j1 Next i2 Next i1 Else For j1 = 1 To IIf(i = 4, N - IC, T - IC) For i1 = 1 To IIf(i = 4, N, T) For i2 = 1 To IIf(i = 4, T, N) If i = 4 Then i3 = T * (i1 - 1) + i2 Else i3 = T * (i2 - 1) + i1 If i1 = j1 Then xy_(i3, j1) = 1 Else xy_(i3, j1) = 0 Next i2 Next i1 Next j1 For i1 = 1 To NT For j1 = 1 To k + 1 xy_(i1, j1 + IIf(i = 4, N - IC, T - IC)) = XY(i1, j1) Next j1 Next i1 End If ElseIf (i = 5 Or i = 6 Or i = 7 Or i = 9 Or i = 10 Or i = 11) Then If i <= 7 Then titol1 = "MODELO DE EFECTOS ALEATORIOS LO NGITUDINALES " & v_est(i - 4) S2_E(i - 4) = SSE(4) / IIf(i = 5, NT, (N * (T - 1)) - (k - IC)) Else titol1 = "MODELO DE EFECTOS ALEATORIOS TE MPORALES " & v_est(i - 8) S2_E(i - 8) = SSE(8) / IIf(i = 9, NT, (T * (N - 1)) - (k - IC)) End If If (i = 5 Or i = 9) Then ReDim aux1(1 To 2) For i1 = 1 To IIf(i = 5, N, T) aux1(1) = aux1(1) + (MU(i1) ^ 2) If IC = 1 Then aux1(2) = aux1(2) + MU (i1) Else aux1(2) = 0 Next i1 If i = 5 Then S2_I(i - 4) = (aux1(1) - (( aux1(2) ^ 2) / N)) / (N - 1) If i = 9 Then S2_T(i - 8) = (aux1(1) - (( aux1(2) ^ 2) / T)) / (T - 1) Else If (i = 6 Or i = 10) Then ReDim aux1(1 To 1) If i = 6 Then aux1(1) = (T * SSE(2) / (N - k)) - S2_E(i - 4) If aux1(1) > 0 Then S2_I(i - 4) = a ux1(1) / T Else S2_I(i - 4) = 0 Else aux1(1) = (N * SSE(3) / (T - k)) - S2_E(i - 8) If aux1(1) > 0 Then S2_T(i - 8) = a ux1(1) / N Else S2_T(i - 8) = 0 End If Else ReDim aux1(1 To ncols - 1, 1 To ncols - 1), aux2(1 To ncols - 1, 1 To ncols - 1) For i1 = 1 To ncols - 1 For j1 = i1 To ncols - 1 For i2 = 1 To IIf(i = 7, N, T) If i = 7 Then aux2(i1, j1 ) = aux2(i1, j1) + (T * XY_I(i2, i1) * XY_I(i2, j1) ) If i = 11 Then aux2(i1, j 1) = aux2(i1, j1) + (N * XY_T(i2, i1) * XY_T(i2, j1 )) Next i2 If i1 <> j1 Then aux2(j1, i1) = aux2(i1, j1) Next j1 Next i1 For i1 = 1 To ncols - 1 For j1 = 1 To ncols - 1

Page 101: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

100

For k1 = 1 To ncols - 1 aux1(i1, j1) = aux1(i1, j1 ) + (MMCO(i1, k1, 1) * aux2(k1, j1)) Next k1 Next j1 Next i1 traza = 0 For i1 = 1 To ncols - 1 traza = traza + aux1(i1, i1) Next i1 If i = 7 Then aux1(1, 1) = SSE(1) - ((NT - k) * S 2_E(i - 4)) If aux1(1, 1) > 0 Then S2_I(i - 4) = aux1(1, 1) / (NT - (T * traza)) Else S2_I(i - 4) = 0 Else aux1(1, 1) = SSE(1) - ((NT - k) * S 2_E(i - 8)) If aux1(1, 1) > 0 Then S2_T(i - 8) = aux1(1, 1) / (NT - (N * traza)) Else S2_T(i - 8) = 0 End If End If End If If i <= 7 Then If S2_I(i - 4) <> 0 Then a(1, 1) = 1 - Sqr(S2_E(i - 4) / (S2_E( i - 4) + (T * S2_I(i - 4)))) Else avis = True a(1, 1) = 0 End If Else If S2_T(i - 8) <> 0 Then a(1, 1) = 1 - Sqr(S2_E(i - 8) / (S2_E( i - 8) + (N * S2_T(i - 8)))) Else avis = True a(1, 1) = 0 End If End If For i1 = 1 To IIf(i <= 7, N, T) For i2 = 1 To IIf(i <= 7, T, N) If i <= 7 Then i3 = T * (i1 - 1) + i 2 Else i3 = T * (i2 - 1) + i1 For j1 = 1 To ncols If i <= 7 Then xy_(i3, j1) = XY( i3, j1) - (a(1, 1) * XY_I(i1, j1)) If i >= 9 Then xy_(i3, j1) = XY( i3, j1) - (a(1, 1) * XY_T(i1, j1)) Next j1 Next i2 Next i1 If avis Then titol1 = titol1 & " " & Chr(222 ) & " s" & Chr(178) & IIf(i <= 7, "(i) < 0", "(t) < 0") ElseIf i = 12 Then titol1 = "MODELO DE EFECTOS FIJOS LONGITUDIN ALES Y TEMPORALES" If Not IMP_F Then For i1 = 1 To N For i2 = 1 To T i3 = T * (i1 - 1) + i2 For j1 = 1 To ncols xy_(i3, j1) = XY(i3, j1 + IC) - XY_I(i1, j1 + IC) Next j1 Next i2 Next i1 For i1 = 1 To T For i2 = 1 To N i3 = T * (i2 - 1) + i1 For j1 = 1 To ncols xy_(i3, j1) = xy_(i3, j1) - X Y_T(i1, j1 + IC) + mean(j1 + IC) Next j1 Next i2 Next i1 Else For j1 = 1 To N - IC For i1 = 1 To N For i2 = 1 To T i3 = T * (i1 - 1) + i2 If i1 = j1 Then xy_(i3, j1) = 1 Else xy_(i3, j1) = 0 Next i2 Next i1 Next j1 For j1 = 1 To T - 1 For i1 = 1 To T For i2 = 1 To N i3 = T * (i2 - 1) + i1 If i1 = j1 Then xy_(i3, j1 + (N - IC)) = 1 Else xy_(i3, j1 + (N - IC)) = 0 Next i2 Next i1 Next j1 For i1 = 1 To NT For j1 = 1 To k + 1 xy_(i1, j1 + (N - IC) + (T - 1)) = XY(i1, j1) Next j1

Page 102: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

101

Next i1 End If ElseIf i >= 13 And i <= 15 Then titol1 = "MODELO DE EFECTOS ALEATORIOS LONGI TUDINALES Y TEMPORALES " & v_est(i - IIf(i <> 15, 1 2, 11)) S2_E(i - 12) = SSE(12) / IIf(i = 13, NT, (N - 1) * (T - 1) - (k - IC)) If i = 13 Then For i2 = 1 To 2 ReDim aux1(1 To 2) For i1 = 1 To IIf(i2 = 1, N, T) aux1(1) = aux1(1) + MU(i1, IIf(i2 = 1, 1, 2)) ^ 2 If IC = 1 Then aux1(2) = aux1(2) + MU(i1, IIf(i2 = 1, 1, 2)) Else aux1(2) = 0 Next i1 If i2 = 1 Then S2_I(i - 12) = (aux1(1 ) - ((aux1(2) ^ 2) / N)) / (N - 1) If i2 = 2 Then S2_T(i - 12) = (aux1(1 ) - ((aux1(2) ^ 2) / T)) / (T - 1) Next i2 ElseIf i = 14 Then ReDim aux1(1 To 2) aux1(1) = (T * SSE(2) / (N - k)) - S2_E(i - 12) If aux1(1) > 0 Then S2_I(i - 12) = aux1(1 ) / T Else S2_I(i - 12) = 0 aux1(2) = (N * SSE(3) / (T - k)) - S2_E(i - 12) If aux1(2) > 0 Then S2_T(i - 12) = aux1(2 ) / N Else S2_T(i - 12) = 0 ElseIf i = 15 Then For i4 = 1 To 2 ReDim maux(1 To ncols, 1 To ncols) For i1 = 1 To IIf(i4 = 1, T, N) For i2 = 1 To IIf(i4 = 1, N, T) If i4 = 1 Then i3 = T * (i2 - 1) + i1 Else i3 = T * (i1 - 1) + i2 For j1 = 1 To ncols If i4 = 1 Then xy_(i3, j1 ) = XY(i3, j1) - XY_T(i1, j1) + mean(j1) If i4 = 2 Then xy_(i3, j1 ) = XY(i3, j1) - XY_I(i1, j1) + mean(j1) Next j1 Next i2 Next i1 For i1 = 1 To obs For j1 = 1 To ncols For k1 = j1 To ncols maux(j1, k1) = maux(j1, k 1) + (xy_(i1, j1) * xy_(i1, k1)) Next k1 Next j1 Next i1 For j1 = 1 To ncols For k1 = j1 + 1 To ncols maux(k1, j1) = maux(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, IC, maux, obs, ncol s, 0.00000001, False) ReDim aux1(1 To ncols - 1, 1 To ncols - 1), aux2(1 To ncols - 1, 1 To ncols - 1) For i1 = 1 To ncols - 1 For j1 = i1 To ncols - 1 For i2 = 1 To IIf(i4 = 1, N, T) If i4 = 1 Then aux2(i1, j 1) = aux2(i1, j1) + (T * XY_I(i2, i1) * XY_I(i2, j1 )) If i4 = 2 Then aux2(i1, j 1) = aux2(i1, j1) + (N * XY_T(i2, i1) * XY_T(i2, j1 )) Next i2 If i1 <> j1 Then aux2(j1, i1) = aux2(i1, j1) Next j1 Next i1 For i1 = 1 To ncols - 1 For j1 = 1 To ncols - 1 For k1 = 1 To ncols - 1 aux1(i1, j1) = aux1(i1, j 1) + (maux(i1, k1) * aux2(k1, j1)) Next k1 Next j1 Next i1 traza = 0 For i1 = IC + 1 To ncols - 1 traza = traza + aux1(i1, i1) Next i1 If i4 = 1 Then aux1(1, 1) = maux(ncols, ncols) - ((T * (N - 1) - (k - IC)) * S2_E(i - 12)) If aux1(1, 1) > 0 Then S2_I(i - 12 ) = aux1(1, 1) / (T * (N - 1) - (T * traza)) Else S 2_I(i - 12) = 0 Else aux1(1, 1) = maux(ncols, ncols) - ((N * (T - 1) - (k - IC)) * S2_E(i - 12)) If aux1(1, 1) > 0 Then S2_T(i - 12 ) = aux1(1, 1) / (N * (T - 1) - (N * traza)) Else S 2_T(i - 12) = 0 End If Next i4 End If a(1, 2) = 0 a(2, 2) = 0 If S2_I(i - 12) > 0 Then a(1, 2) = 1 - Sqr(S2_E(i - 12) / (S2_E(i - 12) + (T * S2_I(i - 12)))) a(2, 2) = 1 - Sqr(S2_E(i - 12) / (S2_E(i - 12) + (N * S2_T(i - 12))))

Page 103: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

102

End If If (a(1, 2) > 0 And a(2, 2) > 0) Then a(3, 2) = a(1, 2) + a(2, 2) - 1 + Sqr(S2 _E(i - 12) / (S2_E(i - 12) + (T * S2_I(i - 12)) + ( N * S2_T(i - 12)))) Else avis = True a(3, 2) = 0 End If For i1 = 1 To N For i2 = 1 To T i3 = T * (i1 - 1) + i2 For j1 = 1 To ncols xy_(i3, j1) = XY(i3, j1) - (a(1, 2) * XY_I(i1, j1)) Next j1 Next i2 Next i1 For i1 = 1 To T For i2 = 1 To N i3 = T * (i2 - 1) + i1 For j1 = 1 To ncols xy_(i3, j1) = xy_(i3, j1) - (a(2 , 2) * XY_T(i1, j1)) + (a(3, 2) * mean(j1)) Next j1 Next i2 Next i1 If avis Then If a(1, 2) = 0 Then titol1 = titol1 & " " & Chr(222) & " s" & Chr(178) & "(i) < 0" If a(2, 2) = 0 Then If a(1, 2) = 0 Then titol1 = titol1 & " y s" & Chr(178) & "(t) < 0" _ Else titol1 = titol1 & " " & Chr(222) & " s" & Chr(178) & "(t) < 0" End If End If End If For i1 = 1 To obs For j1 = 1 To ncols For k1 = j1 To ncols m(j1, k1) = m(j1, k1) + (xy_(i1, j1 ) * xy_(i1, k1)) Next k1 Next j1 Next i1 For j1 = 1 To ncols For k1 = j1 + 1 To ncols m(k1, j1) = m(j1, k1) Next k1 Next j1 If (i <> 4 And i <> 8 And i <> 12) Then ReDim aux1(1 To 1) For i1 = 1 To obs aux1(1) = aux1(1) + xy_(i1, ncols) Next i1 SST(i) = m(ncols, ncols) - ((aux1(1) ^ 2) / obs) Else SST(i) = SST(1) End If Call C_G2SWEEP(1, IC, m, obs, ncols, 0.00000001 , False) If (i = 4 Or i = 8 Or i = 12) Then If (OPT(6, 1) Or OPT(9, 1) Or OPT(13, 1)) Th en Call M2_03_EFECTES_FIXES(i, m, ncols) End If SSE(i) = m(ncols, ncols) If (i = 4 Or i = 8 Or i = 12) Then i1 = 0 If i = 4 Then If IMP_F Then i1 = N i2 = 2 ElseIf i = 8 Then If IMP_F Then i1 = T i2 = 3 Else If IMP_F Then i1 = N + T - 1 i2 = 4 End If For i3 = i1 + 1 To ncols For j1 = i1 + 1 To ncols MMCO(i3 - i1, j1 - i1, i2) = m(i3, j1) Next j1 Next i3 End If salta: If i = 1 Then Call M2_04_ESCRIPTURA_MODELS(0, 0 , 0, 0, avis, "") If OPT(i, 2) Then Call M2_04_ESCRIPTURA_MODELS(i, GL, m, ncols , avis, titol1) If (i <> 4 And i <> 8 And i <> 12) Then If Not avis Then

Page 104: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

103

If (N <= 2000 And T <= 2000) Then Cal l M2_051_TEST_PANEL(i, mean, a) End If If i = 1 Then Call M2_052_TEST_BREUSCH(1) Else If Not avis Then Call M2_053_TEST_HAU SMAN(i, GL, m) End If Else Call M2_054_TEST_FIXES(i, GL) End If End If SALTA2: Next i End Sub Private Sub M2_03_EFECTES_FIXES(bucle As Integer, m , ncols) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''' 'Càlcul dels efectes longitudinals i/o temporals en els models d'efectes fixs' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''' Dim i1 As Long, j1 As Long If bucle = 4 Then ReDim MU(1 To N) For i1 = 1 To N For j1 = 1 To IIf(IMP_F = False, ncols - 1, k - IC) If Not IMP_F Then MU(i1) = MU(i1) + (m(j1, ncols) * XY_ I(i1, j1 + IC)) Else MU(i1) = MU(i1) + (m(j1 + N, ncols) * XY_I(i1, j1 + IC)) End If Next j1 MU(i1) = XY_I(i1, IIf(IMP_F = False, ncols, k) + IC) - MU(i1) Next i1 ElseIf bucle = 8 Then ReDim MU(1 To T) For i1 = 1 To T For j1 = 1 To IIf(IMP_F = False, ncols - 1, k - IC) If Not IMP_F Then MU(i1) = MU(i1) + (m(j1, ncols) * XY_ T(i1, j1 + IC)) Else MU(i1) = MU(i1) + (m(j1 + T, ncols) * XY_T(i1, j1 + IC)) End If Next j1 MU(i1) = XY_T(i1, IIf(IMP_F = False, ncols, k) + IC) - MU(i1) Next i1 Else ReDim MU(1 To Application.max(N, T), 1 To 2) For i1 = 1 To N For j1 = 1 To IIf(IMP_F = False, ncols - 1, k - IC) If Not IMP_F Then MU(i1, 1) = MU(i1, 1) + (m(j1, ncols) * XY_I(i1, j1 + IC)) Else MU(i1, 1) = MU(i1, 1) + (m(j1 + N + T - 1, ncols) * XY_I(i1, j1 + IC)) End If Next j1 MU(i1, 1) = XY_I(i1, IIf(IMP_F = False, ncol s, k) + IC) - MU(i1, 1) Next i1 For i1 = 1 To T For j1 = 1 To IIf(IMP_F = False, ncols - 1, k - IC) If Not IMP_F Then MU(i1, 2) = MU(i1, 2) + (m(j1, ncols) * XY_T(i1, j1 + IC)) Else MU(i1, 2) = MU(i1, 2) + (m(j1 + T + N - 1, ncols) * XY_T(i1, j1 + IC)) End If Next j1 MU(i1, 2) = XY_T(i1, IIf(IMP_F = False, ncol s, k) + IC) - MU(i1, 2) Next i1 End If End Sub Private Sub M2_04_ESCRIPTURA_MODELS(i, GL, m, ncols , avis, titol1) ''''''''''''''''''''''''' 'ANÀLISI DE LA VARIÀNCIA' ''''''''''''''''''''''''' Dim i1 As Long If i = 0 Then ReDim R(1 To 4, 1 To 3) R(1, 1) = "Variable dependiente"

Page 105: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

104

R(2, 1) = "Observaciones longitudinales" R(3, 1) = "Observaciones temporales" R(4, 1) = "Total observaciones" R(1, 3) = LVAR(k + 1, 2) R(2, 3) = N R(3, 3) = T R(4, 3) = NT Call M2_ESCRIPTURA(0, 37, 0, avis, "Información general de la estimación", "") Exit Sub ElseIf (i = 1 Or i = 4 Or i = 8 Or i = 12) Then ReDim R(1 To 2, 1 To 5) ElseIf i < 13 Then ReDim R(1 To 2, 1 To 7) Else ReDim R(1 To 2, 1 To IIf(avis, 5, 8)) End If ReDim S2X(1 To 15) As Double S2X(i) = SSE(i) / GL(i) R(1, 1) = "SCE" R(2, 1) = SSE(i) R(1, 2) = "gl" R(2, 2) = GL(i) R(1, 3) = "ECM" R(2, 3) = S2X(i) R(1, 4) = Chr(214) & "ECM" R(2, 4) = Sqr(S2X(i)) R(1, 5) = "R" & Chr(178) If (i = 1 Or i = 4 Or i = 8 Or i = 12) Then R(2, 5) = 1 - (SSE(i) / SST(IIf(i = 1, i, 1))) Else R(2, 5) = 1 - (SSE(i) / SST(i)) If (i >= 5 And i <= 7) Then R(1, 6) = "s" & Chr(178) & "(i)" R(2, 6) = S2_I(i - 4) R(1, 7) = "s" & Chr(178) & "(error)" R(2, 7) = S2_E(i - 4) ElseIf (i >= 9 And i <= 11) Then R(1, 6) = "s" & Chr(178) & "(t)" R(2, 6) = S2_T(i - 8) R(1, 7) = "s" & Chr(178) & "(error)" R(2, 7) = S2_E(i - 8) Else If Not avis Then R(1, 6) = "s" & Chr(178) & "(i)" R(2, 6) = S2_I(i - IIf(i <> 16, 12, 13)) R(1, 7) = "s" & Chr(178) & "(t)" R(2, 7) = S2_T(i - IIf(i <> 16, 12, 13)) R(1, 8) = "s" & Chr(178) & "(error)" R(2, 8) = S2_E(i - IIf(i <> 16, 12, 13)) End If End If End If Call M2_ESCRIPTURA(1, 37, i, avis, titol1, "") ''''''''''' 'ESTIMACIÓ' ''''''''''' ReDim R(1 To ncols + 1, 1 To 5) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "Error" & Chr(10) & "Estándar" R(1, 4) = "Valor t" R(1, 5) = "Prob |t|" For i1 = 1 To ncols - 1 If (i <> 4 And i <> 8 And i <> 12) Then R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & ")" Else If Not IMP_F Then R(i1 + 2, 1) = "b" & i1 + 1 & "(" & LVAR (i1 + 1, 2) & ")" Else If i = 4 Then If i1 <= N - IC Then R(i1 + 2, 1) = "m(" & i1 & ")" Else R(i1 + 2, 1) = "b" & i1 - (N - IC) & "(" & LVAR(i1 - (N - IC), 2) & ")" End If ElseIf i = 8 Then If i1 <= T - IC Then R(i1 + 2, 1) = "l(" & i1 & ")" Else R(i1 + 2, 1) = "b" & i1 - (T - IC) & "(" & LVAR(i1 - (T - IC), 2) & ")" End If

Page 106: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

105

Else If i1 <= N - IC Then R(i1 + 2, 1) = "m(" & i1 & ")" ElseIf i1 <= (N - IC) + (T - 1) Then R(i1 + 2, 1) = "l(" & i1 - (N - IC ) & ")" Else R(i1 + 2, 1) = "b" & i1 - (N - IC) - (T - 1) & "(" & LVAR(i1 - (N - IC) - (T - 1), 2) & ")" End If End If End If End If R(i1 + 2, 2) = m(i1, ncols) R(i1 + 2, 3) = Sqr(S2X(i) * m(i1, i1)) R(i1 + 2, 4) = R(i1 + 2, 2) / R(i1 + 2, 3) R(i1 + 2, 5) = Application.TDist(Abs(R(i1 + 2, 4)), GL(i), 2) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0. 0001", R(i1 + 2, 5)) Next i1 Call M2_ESCRIPTURA(2, 37, i, avis, "", "") End Sub Private Sub M2_051_TEST_PANEL(bucle, mean, a) Dim gln(1 To 2) As Long, gld(1 To 2) As Long, i1 As Long, i2 As Long, _ i3 As Long, i4 As Integer, j1 As Integer, k1 As Integer, m() As Double, _ panel(1 To 2) As Double, xy_() As Double, xy_au x() As Double If bucle <> 1 And bucle < 13 Then ReDim xy_aux(1 To NT, 1 To k + 1) For i1 = 1 To IIf(bucle <= 7, N, T) For i2 = 1 To IIf(bucle <= 7, T, N) If bucle <= 7 Then i3 = T * (i1 - 1) + i 2 Else i3 = T * (i2 - 1) + i1 For j1 = 1 To k + 1 If bucle <= 7 Then xy_aux(i3, j1) = XY(i3, j1) - (a(1, 1) * XY_I(i1, j1)) If bucle >= 9 Then xy_aux(i3, j1) = XY(i3, j1) - (a(1, 1) * XY_T(i1, j1)) Next j1 Next i2 Next i1 End If If bucle >= 13 Then ReDim xy_aux(1 To NT, 1 To k + 1) For i1 = 1 To N For i2 = 1 To T i3 = T * (i1 - 1) + i2 For j1 = 1 To k + 1 xy_aux(i3, j1) = XY(i3, j1) - (a(1, 2) * XY_I(i1, j1)) Next j1 Next i2 Next i1 For i1 = 1 To T For i2 = 1 To N i3 = T * (i2 - 1) + i1 For j1 = 1 To k + 1 xy_aux(i3, j1) = xy_aux(i3, j1) - (a (2, 2) * XY_T(i1, j1)) + (a(3, 2) * mean(j1)) Next j1 Next i2 Next i1 End If For i4 = 1 To 2 panel(i4) = 0 For i3 = 1 To IIf(i4 = 1, N, T) ReDim m(1 To k + 1, 1 To k + 1), xy_(1 To I If(i4 = 1, T, N), 1 To k + 1) For i2 = 1 To IIf(i4 = 1, T, N) i1 = IIf(i4 = 1, T * (i3 - 1) + i2, T * (i2 - 1) + i3) For j1 = 1 To k + 1 If bucle = 1 Then xy_(i2, j1) = XY(i1, j1) Else xy_(i2, j1) = xy_aux(i1, j1) End If Next j1 Next i2 For i1 = 1 To IIf(i4 = 1, T, N) For j1 = 1 To k + 1 For k1 = j1 To k + 1 m(j1, k1) = m(j1, k1) + (xy_(i1 , j1) * xy_(i1, k1)) Next k1 Next j1 Next i1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1

Page 107: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

106

Call C_G2SWEEP(1, IC, m, IIf(i4 = 1, T, N), k + 1, 0.00000001, False) panel(i4) = panel(i4) + m(k + 1, k + 1) Next i3 gln(i4) = IIf(i4 = 1, k * (N - 1), k * (T - 1)) gld(i4) = IIf(i4 = 1, N * (T - k), T * (N - k)) panel(i4) = ((SSE(bucle) - panel(i4)) / gln(i4) ) / (panel(i4) / gld(i4)) Next i4 ReDim R(1 To 3, 1 To 4) R(1, 1) = "Hipótesis nula" R(1, 2) = "Valor F" R(1, 3) = "gl" R(1, 4) = "Prob > F" For i1 = 1 To 2 R(i1 + 1, 1) = IIf(i1 = 1, "b(i) = b", "b(t) = b") R(i1 + 1, 2) = IIf(panel(i1) > 0, panel(i1), "- ----") R(i1 + 1, 3) = IIf(panel(i1) > 0, Format(gln(i1 ), "#####0") & " y " & Format(gld(i1), "#####0"), " -----") R(i1 + 1, 4) = IIf(panel(i1) > 0, Application.F Dist(R(i1 + 1, 2), gln(i1), gld(i1)), "-----") If panel(i1) > 0 Then R(i1 + 1, 4) = IIf(R(i1 + 1, 4) < 0.0001, "< 0.0001", R(i1 + 1, 4)) Next i1 Call M2_ESCRIPTURA(3, 37, 1, False, "Test de 'panel abilidad'", "F") End Sub Private Sub M2_052_TEST_BREUSCH(opcio As Integer) Dim gln As Integer, i1 As Long, i2 As Long, i3 As L ong, i4 As Integer, j1 As Integer ReDim bp(1 To 3) As Double, aux(1 To 3) As Double For i4 = 1 To 2 aux(3) = 0 For i1 = 1 To IIf(i4 = 1, N, T) aux(2) = 0 For i2 = 1 To IIf(i4 = 1, T, N) If i4 = 1 Then i3 = T * (i1 - 1) + i2 E lse i3 = T * (i2 - 1) + i1 aux(1) = 0 For j1 = 1 To k aux(1) = aux(1) + (XY(i3, j1) * MMC O(j1, k + 1, 1)) Next j1 aux(2) = aux(2) + (XY(i3, k + 1) - aux( 1)) Next i2 aux(3) = aux(3) + (aux(2) ^ 2) Next i1 bp(i4) = (NT / (2 * IIf(i4 = 1, T - 1, N - 1))) * (((aux(3) / SSE(1)) - 1) ^ 2) Next i4 bp(3) = bp(1) + bp(2) ReDim R(1 To 4, 1 To 4) R(1, 1) = "Hipótesis nula" R(1, 2) = "Valor c" & Chr(178) R(1, 3) = "gl" R(1, 4) = "Prob > c" & Chr(178) For i1 = 1 To 3 R(i1 + 1, 1) = "s" & Chr(178) & IIf(i1 = 1, "(i )=0", "(t)=0") If i1 = 3 Then R(i1 + 1, 1) = "s" & Chr(178) & "(i)=s" & Chr(178) & "(t)=0" R(i1 + 1, 2) = IIf(bp(i1) > 0, bp(i1), "-----") R(i1 + 1, 3) = IIf(bp(i1) > 0, IIf(i1 <> 3, 1, 2), "-----") R(i1 + 1, 4) = IIf(bp(i1) > 0, Application.ChiD ist(R(i1 + 1, 2), R(i1 + 1, 3)), "-----") If bp(i1) > 0 Then R(i1 + 1, 4) = IIf(R(i1 + 1, 4) < 0.0001, "< 0.0001", R(i1 + 1, 4)) Next i1 Call M2_ESCRIPTURA(3, 37, 1, False, "Test de Breusc h-Pagan: efectos aleatorios nulos", "") End Sub Private Sub M2_054_TEST_FIXES(i, GL) Dim gln As Long, gld As Long, i1 As Integer, i2 As Integer i2 = IIf(i <> 12, 0, 1) ReDim R(1 To IIf(i <> 12, 2, 4), 1 To 4 + i2) R(1, 1) = "Hipótesis nula" R(1, 2 + i2) = "Valor F" R(1, 3 + i2) = "gl" R(1, 4 + i2) = "Prob > F" For i1 = 1 To IIf(i <> 12, 1, 3) gld = GL(i) If i = 4 Then gln = GL(1) - GL(4) R(i1 + 1, 1) = "m(i) = 0" R(i1 + 1, 2) = ((SSE(1) - SSE(4)) / gln) / ( SSE(4) / gld) ElseIf i = 8 Then gln = GL(1) - GL(8) R(i1 + 1, 1) = "l(t) = 0" R(i1 + 1, 2) = ((SSE(1) - SSE(8)) / gln) / ( SSE(8) / gld) ElseIf i = 12 Then If i1 = 1 Then gln = GL(1) - GL(12) R(i1 + 1, 1) = "m(i) = l(t) = 0"

Page 108: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

107

R(i1 + 1, 3) = ((SSE(1) - SSE(12)) / gln) / (SSE(12) / gld) ElseIf i1 = 2 Then gln = GL(4) - GL(12) R(i1 + 1, 1) = "m(i) " & Chr(185) & " 0 | l(t) = 0" R(i1 + 1, 3) = ((SSE(4) - SSE(12)) / gln) / (SSE(12) / gld) Else gln = GL(8) - GL(12) R(i1 + 1, 1) = "l(t) = 0 | m(i) " & Chr (185) & " 0" R(i1 + 1, 3) = ((SSE(8) - SSE(12)) / gln) / (SSE(12) / gld) End If End If R(i1 + 1, 2 + i2) = IIf(R(i1 + 1, 2 + i2) > 0, R(i1 + 1, 2 + i2), "-----") R(i1 + 1, 3 + i2) = IIf(R(i1 + 1, 2 + i2) > 0, Format(gln, "#####0") & " y " & Format(gld, "#####0 "), "-----") R(i1 + 1, 4 + i2) = IIf(R(i1 + 1, 2 + i2) > 0, Application.FDist(R(i1 + 1, 2 + i2), gln, gld), "-- ---") If R(i1 + 1, 2 + i2) > 0 Then R(i1 + 1, 4 + i2) = IIf(R(i1 + 1, 4 + i2) < 0.0001, "< 0.0001", R(i1 + 1, 4 + i2)) Next i1 Call M2_ESCRIPTURA(3, 37, i, False, "Test de efecto s fijos nulos", "F") End Sub Private Sub M2_053_TEST_HAUSMAN(i, GL, m) Dim alert As Boolean, h As Double, i1 As Integer, i 2 As Integer, i3 As Integer, i4 As Integer, j1 As I nteger i4 = IIf(i > 11, 1, 0) ReDim aux(1 To k - IC + 1, 1 To k - IC + 1) As Doub le, beta(1 To k - IC) As Double, R(1 To 2, 1 To 4 + i4) If i <= 7 Then i2 = 2 i3 = 4 R(2, 1) = "E[m(i) | X)]=0" ElseIf i <= 11 Then i2 = 3 i3 = 8 R(2, 1) = "E[l(t) | X)]=0" Else i2 = 4 i3 = 12 R(2, 1) = "E[m(i) , l(t) | X]=0" End If For i1 = 1 To k - IC beta(i1) = MMCO(i1, k + 1 - IC, i2) - m(i1 + IC , k + 1) For j1 = 1 To k - IC aux(i1, j1) = ((SSE(i3) / GL(i3)) * MMCO(i 1, j1, i2)) - ((SSE(i) / GL(i)) * m(i1 + IC, j1 + I C)) Next j1 Next i1 Call M2_053_TEST_HAUSMAN_G2SWEEP(aux, k - IC + 1, 0 .0000000000001) For i1 = 1 To k - IC For j1 = 1 To k - IC h = h + (beta(i1) * aux(i1, j1) * beta(j1)) Next j1 Next i1 alert = IIf(h <= 0, True, False) R(1, 1) = "Hipótesis nula" R(1, 2 + i4) = "Valor c" & Chr(178) R(1, 3 + i4) = "gl" R(1, 4 + i4) = "Prob > c" & Chr(178) R(2, 2 + i4) = IIf(alert = False, h, "-----") R(2, 3 + i4) = IIf(alert = False, k - IC, "-----") R(2, 4 + i4) = IIf(alert = False, Application.ChiDi st(R(2, 2 + i4), R(2, 3 + i4)), "-----") If Not alert Then R(2, 4 + i4) = IIf(R(2, 4 + i4) < 0.0001, "< 0.0001", R(2, 4 + i4)) Call M2_ESCRIPTURA(3, 37, i, False, "Test de Hausma n: efectos fijos vs. efectos aleatorios" & _ IIf(alert = True, " (No computable !!)", ""), "") End Sub Sub M2_053_TEST_HAUSMAN_G2SWEEP(m, ncols, vtol As D ouble) ''''''''''''''''''' 'ALGORITME G2SWEEP' ''''''''''''''''''' Dim d1 As Double, d2 As Double, i1 As Integer, i2 A s Integer, i3 As Integer, j1 As Integer ReDim aux(1 To ncols) As Double, tol(1 To ncols - 1 ) As Double '''''''''''''''''''''''' 'Defineix la tolerància' '''''''''''''''''''''''' For i1 = 1 To ncols - 1 tol(i1) = vtol Next i1

Page 109: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

108

For i1 = 1 To ncols - 1 For i2 = i1 To i1 d1 = m(i2, i2) For j1 = 1 To ncols m(i2, j1) = m(i2, j1) / d1 aux(j1) = m(i2, j1) Next j1 Next i2 For i2 = 1 To ncols If i2 <> i1 Then d2 = m(i2, i1) For j1 = 1 To ncols m(i2, j1) = m(i2, j1) - (d2 * aux(j1 )) Next j1 m(i2, i1) = -d2 / d1 End If Next i2 m(i1, i1) = 1 / d1 Next i1 End Sub Private Sub M2_ESCRIPTURA(opcio As Integer, color A s Integer, i, avis, titol1, Tipus As String) Sheets(FULL_R).Activate Dim c(1 To 2) As Integer, i1 As Integer, j1 As Inte ger, m1 As Double, m2 As Double '''''''''''''''''''' 'Escriptura general' '''''''''''''''''''' c(1) = UBound(R, 1) c(2) = UBound(R, 2) With Range(Cells(F - IIf(opcio = 2, 1, 2), 1), Cell s(F + c(1) - 1, 10)) .ColumnWidth = 9.5 With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter .Interior.ColorIndex = 2 .RowHeight = 11 .VerticalAlignment = xlCenter End With m1 = 10 ^ (-6) m2 = 10 ^ (6) With Cells(F - 1, 1) .Font.Bold = True .HorizontalAlignment = xlLeft .Value = titol1 If avis Then .Characters(81, 3).Font.Name = "symbol" .Characters(81, 3).Font.Bold = True .Characters(91, 1).Font.Name = "symbol" .Characters(91, 1).Font.Bold = True End If End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) .Borders(xlEdgeTop).LineStyle = xlDouble .Borders(xlEdgeBottom).LineStyle = xlDouble .Interior.ColorIndex = color .Value = R End With If opcio <> 0 Then If opcio <> 2 Then j1 = 0 Else i1 = 1 For j1 = 1 To c(2) With Range(Cells(F, j1), Cells(F + i1, j1 )) .Borders(xlEdgeBottom).LineStyle = xlCo ntinuous .MergeCells = True .WrapText = True .Font.Bold = True End With Next j1 End If If opcio <> 1 Then With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Font.Bold = True .HorizontalAlignment = xlLeft End With End If '''''''''''''''''''''''''''''''''''''''''

Page 110: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

109

'Escriptura característica de cada opció' ''''''''''''''''''''''''''''''''''''''''' If opcio = 0 Then For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , 2)).MergeCells = True Next i1 Range(Cells(F, c(2)), Cells(F + c(1) - 1, c(2))) .HorizontalAlignment = xlRight ElseIf opcio = 1 Then Range(Cells(F, 1), Cells(F, c(2))).VerticalAlign ment = xlCenter For j1 = 1 To c(2) If j1 <> 2 And j1 <> 5 Then With Range(Cells(F + 1, j1), Cells(F + 1 , j1)) If R(2, j1) >= m1 And R(2, j1) <= m2 T hen .NumberFormat = "#####0.000000" End With End If Next j1 Range(Cells(F, 2), Cells(F + c(1) - 1, 2)).Numbe rFormat = "0" Range(Cells(F, 5), Cells(F + c(1) - 1, 5)).Numbe rFormat = "0.0000" Cells(F, 4).Characters(1, 1).Font.Name = "symbol " Cells(F, 4).Characters(1, 1).Font.Bold = True If (i <> 4 And i <> 8 And i <> 12) Then For j1 = 1 To IIf(i < 12, 2, 3) Cells(F, j1 + 5).Characters(1, 1).Font.N ame = "symbol" Cells(F, j1 + 5).Characters(1, 1).Font.B old = True Next j1 End If ElseIf opcio = 2 Then Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Name = "symbol" Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Bold = True For i1 = 2 To c(1) For j1 = 2 To 3 With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= m1 And Abs(R(i1, j1)) <= m2 Then .NumberFormat = "#####0.000000" End With Next j1 Next i1 Range(Cells(F, 4), Cells(F + c(1) - 1, 4)).Numbe rFormat = "#####0.000" Range(Cells(F, 5), Cells(F + c(1) - 1, 5)).Numbe rFormat = "0.0000" Range(Cells(F, 6), Cells(F + 1, 7)).MergeCells = True If IMP_F And (i = 4 Or i = 8 Or i = 12) Then If i = 4 Then j1 = N - IC If i = 8 Then j1 = T - IC If i = 12 Then j1 = N - IC + T - 1 For i1 = 1 To j1 Cells(F + i1 + 1, 1).Characters(1, 1).Fo nt.Name = "symbol" Cells(F + i1 + 1, 1).Characters(1, 1).Fo nt.Name = True Next i1 End If If avis Then ActiveWindow.SelectedSheets.HPageBr eaks.Add (Cells(F + c(1), 1)) F = F + 1 ElseIf opcio = 3 Then For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , c(2) - 3)).MergeCells = True Cells(F + i1 - 1, c(2) - 2).NumberFormat = " #####0.000" Cells(F + i1 - 1, c(2) - 1).NumberFormat = " #####0" Cells(F + i1 - 1, c(2)).NumberFormat = "0.00 00" Next i1 If Tipus = "F" Then For i1 = 1 To c(1) Cells(F + i1, 1).Characters(1, 1).Font.Na me = "symbol" Cells(F + i1, 1).Characters(1, 1).Font.Bo ld = True If i = 1 Then Cells(F + i1, 1).Characters(8, 1).Font .Name = "symbol" Cells(F + i1, 1).Characters(8, 1).Font .Bold = True ElseIf i = 12 Then If i1 = 1 Then Cells(F + i1, 1).Characters(8, 1).F ont.Name = "symbol" Cells(F + i1, 1).Characters(8, 1).F ont.Bold = True ElseIf i1 = 2 Then Cells(F + i1, 1).Characters(6, 1).F ont.Name = "symbol" Cells(F + i1, 1).Characters(6, 1).F ont.Bold = True Cells(F + i1, 1).Characters(14, 1). Font.Name = "symbol" Cells(F + i1, 1).Characters(14, 1). Font.Bold = True Else Cells(F + i1, 1).Characters(14, 1). Font.Name = "symbol" Cells(F + i1, 1).Characters(14, 1). Font.Bold = True Cells(F + i1, 1).Characters(19, 1). Font.Name = "symbol" Cells(F + i1, 1).Characters(19, 1). Font.Bold = True End If End If Next i1 If i <> 1 Then ActiveWindow.SelectedSheets.HP ageBreaks.Add (Cells(F + c(1), 1))

Page 111: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

110

Else Cells(F, c(2) - 2).Characters(7, 1).Font.Name = "symbol" Cells(F, c(2) - 2).Characters(7, 1).Font.Bold = True Cells(F, c(2)).Characters(8, 1).Font.Name = " symbol" Cells(F, c(2)).Characters(8, 1).Font.Bold = T rue If i = 1 Then For i1 = 2 To c(1) Cells(F + i1 - 1, 1).Characters(1, 1). Font.Name = "symbol" Cells(F + i1 - 1, 1).Characters(1, 1). Font.Bold = True If i1 = c(1) Then Cells(F + i1 - 1, 1).Characters(7, 1).Font.Name = "symbol" Cells(F + i1 - 1, 1).Characters(7, 1).Font.Bold = True End If Next i1 Else Cells(F + 1, 1).Characters(3, 1).Font.Name = "symbol" Cells(F + 1, 1).Characters(3, 1).Font.Bold = True If i > 12 Then Cells(F + 1, 1).Characters( 10, 1).Font.Name = "symbol" If i > 12 Then Cells(F + 1, 1).Characters( 10, 1).Font.Bold = True End If ActiveWindow.SelectedSheets.HPageBreaks.Add ( Cells(F + c(1), 1)) End If End If F = F + c(1) + IIf(opcio = 0 Or opcio = 3, 2, 1) Sheets(FULL).Activate End Sub

Page 112: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

111

Attribute VB_Name = "M3_LogitProbit" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVISEXOGENES As Boolean Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Long, nobs ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then NY = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable endógena.", vbCritical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VX(1 To i2) VX(i2) = i1 NX = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar al menos una variable e xógena.", vbCritical, TITOL Exit Sub End If NPES = 0 For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 For i1 = 1 To NX If NY = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y exógena.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If NY = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y factor de elevación.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If NPES = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(VX(i1), 1) & " no puede ser e xógena y factor de elevación.", vbCritical, TITOL Exit Sub End If Next i1 End If If Application.Count(R_XY.Columns(NY)) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(NY, 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If Application.Count(R_XY.Columns(VX(i1))) <> N Then ERR_LEC = True Me.Hide

Page 113: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

112

MsgBox "Algún valor de la variable " & LVAR(V X(i1), 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If Application.Count(R_XY.Columns(NPES)) <> N Or Application.CountIf(R_XY.Columns(NPES), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N PES, 1) & " es negativo, nulo o no numérico.", vbCr itical, TITOL Exit Sub End If End If If Application.Sum(R_XY.Columns(NY)) <> Application .CountIf(R_XY.Columns(NY), "=1") Then ERR_LEC = True Me.Hide MsgBox "Algún valor de " & LVAR(NY, 1) & " es di stinto de 0 o 1.", vbCritical, TITOL Exit Sub End If If Constante.Value = True Then IC = 1 Else IC = 0 k = IC + NX ReDim G2SWEEP(1 To k + 1, 1 To k + 1), XY(1 To N, 1 To k + 1), PES(1 To N) If NPES <> 0 Then NTPESM = Application.Average(R_XY.Rows.Columns(N PES)) NTPES = Application.Sum(R_XY.Rows.Columns(NPES)) / NTPESM Else NTPESM = 1 NTPES = N End If For i3 = 1 To N If NPES <> 0 Then PES(i3) = R_XY.Rows(i3).Colum ns(NPES) / NTPESM Else PES(i3) = 1 If IC = 1 Then XY(i3, 1) = 1 For i1 = 1 To NX XY(i3, IC + i1) = R_XY.Rows(i3).Columns(VX( i1)) Next i1 XY(i3, k + 1) = R_XY.Rows(i3).Columns(NY) For i1 = 1 To k + 1 For i2 = i1 To k + 1 G2SWEEP(i1, i2) = G2SWEEP(i1, i2) + (XY (i3, i1) * XY(i3, i2) * PES(i3)) Next i2 Next i1 Next i3 For i1 = 1 To k + 1 For i2 = i1 + 1 To k + 1 G2SWEEP(i2, i1) = G2SWEEP(i1, i2) Next i2 Next i1 ERROR_COMBINACIO = False Call C_G2SWEEP(0, IC, G2SWEEP, N, k + 1, 0.00000001 , ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide MsgBox "El modelo no es de rango completo.", vbC ritical, TITOL Exit Sub End If If IC = 1 Then LVAR(1, 2) = "Const." For i1 = 1 To NX LVAR(IC + i1, 2) = LVAR(VX(i1), 1) Next i1 LVAR(k + 1, 2) = LVAR(NY, 1) Call ANALISIS(1) End Sub Private Sub Cancelar_Click() SORTIR = True NPES = 0 Unload Me End Sub Private Sub ANALISIS(opcio As Integer) 'LOGIT y PR OBIT Dim i1 As Integer '''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul ''''''''''''''''''''''''''''''''

Page 114: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

113

ReDim OPT(1 To 9) For i1 = 1 To 9 OPT(i1) = True Next i1 OPT(4) = contrastes.Value OPT(5) = restricciones.Value If k - IC = 1 Then OPT(5) = False OPT(8) = predicciones.Value OPT(9) = roc_curva.Value If logit.Value Then LINK = 1 Else LINK = 2 CONVERG = Val(convergencia.Value) ITER = iteraciones.Value SIG = n_sig.Value Me.Hide End Sub Private Sub EXOGENES(opcio As Integer) Dim i1 As Integer AVISEXOGENES = False For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then AVISEXOGENES = True Exit For End If Next i1 If AVISEXOGENES Then For Each CTL In Me.Controls CTL.Enabled = True Next CTL Else NPES = 0 For Each CTL In Me.Controls If CTL.Name <> "Frame1" And CTL.Name <> "log it" And CTL.Name <> "probit" And _ CTL.Name <> "Label1" And CTL.Name <> "Lab el2" And CTL.Name <> "ys" And _ CTL.Name <> "xs" And CTL.Name <> "Cancela r" Then CTL.Enabled = False Next CTL For i1 = 1 To R_XY.Columns.Count ps.Selected(i1 - 1) = False Next i1 End If End Sub Private Sub logit_Click() If logit Then LINK = 1 End Sub Private Sub probit_Click() If probit Then LINK = 2 End Sub Private Sub ps_Click() Dim i1 As Integer For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 End Sub Private Sub UserForm_Layout() n_sig.Move Height:=12, Left:=200, Top:=65, Width:=4 0 End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() Label2.Enabled = True

Page 115: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

114

xs.Enabled = True End Sub Private Sub xs_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call EXOGENES(1) End Sub

Page 116: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

115

Attribute VB_Name = "M3" Option Explicit Sub M3_(opcio As Integer) '''''''''''''''' 'LOGIT y PROBIT' '''''''''''''''' '''''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' '''''''''''''''''''''''''''''''''''''' 'OPT(1) informació estimació 'OPT(2) informació ajustament 'OPT(3) tests RV,W,ML 'OPT(4) contrasts (M3_04)' 'OPT(5) restriccions (M3_05)' 'OPT(6) estimació 'OPT(7) matriu variances 'OPT(8) prediccions (M3_08)' 'OPT(9) Corba 'ROC' (M3_09)' '''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria3: Mod elos Logit y Probit' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String, vconv(12 ) As String, viter(49) As Integer, vsig(5) As Doubl e For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 For i1 = 0 To 12 vconv(i1) = "1E-" & IIf(i1 < 7, 0, "") & i1 + 3 Next i1 For i1 = 50 To 1 Step -1 viter(50 - i1) = i1 Next i1 For i1 = 5 To 0 Step -1 If i1 > 0 Then vsig(5 - i1) = 0.05 * i1 Else vs ig(5 - i1) = 0.01 Next i1 TITOL = "MicroEconometría: Modelos Logit y Probit" h = Application.min(110, 11 * R_XY.Columns.Count) With M3_LogitProbit .logit.Value = True .ys.Move Height:=h, Top:=65, Width:=90 .ys.List = v .xs.Move Height:=h, Top:=65, Width:=90 .xs.List = v .ps.Move Height:=h, Top:=65, Width:=90 .ps.List = v .convergencia.List = vconv .convergencia.Selected(5) = True .iteraciones.List = viter .iteraciones.Selected(25) = True .n_sig.List = vsig .n_sig.Selected(4) = True End With ERR_LEC = True SORTIR = False Do While ERR_LEC = True M3_LogitProbit.Show If SORTIR Then ERR_LEC = False Loop Unload M3_LogitProbit If SORTIR Then Exit Sub Dim avis As Boolean, i() As Double, it As Integer, lh() As Double, maux() As Double, yuns As Long Call M3_SCORING(avis, i, it, lh, maux, yuns) If OPT(1) Then Call M3_01(avis, it, lh, yuns) If OPT(2) Then Call M3_02(lh) If OPT(3) Then Call M3_03(avis, lh, yuns) If OPT(4) Then Call M3_04(avis, maux) If OPT(5) Then Call M3_05(avis) If OPT(6) Then Call M3_06(avis) If OPT(7) And k > 1 Then Call M3_ESCRIPTURA_1(avis) If OPT(8) Then Call M3_08(1)

Page 117: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

116

If OPT(9) Then Call M3_09(i, yuns) Call M3_09_1(yuns) End If INOU = INOU + 1 End Sub Private Sub M3_SCORING(avis, i, it, lh, maux, yuns) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''' 'Algoritme de càlcul, métode "SCORING" del PROBIT_L OGIT' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''' Dim aux As Double, a1 As Double, a2 As Double, c As Double, cdf As Double, i2 As Integer, _ i3 As Long, j1 As Integer, k1 As Integer, pdf A s Double, pi As Double, Y As Integer, _ z As Double ReDim B(1 To k), d_g(1 To 2 * k) As Double, lh(2) For j1 = 1 To k B(j1) = G2SWEEP(j1, k + 1) Next j1 c = 1 pi = 1 / Sqr(2 * Application.pi) For it = 1 To ITER lh(1) = 0 ReDim MCOV(1 To k + 1, 1 To k + 1) For i3 = 1 To N Y = XY(i3, k + 1) z = 0 For j1 = 1 To k z = z + (XY(i3, j1) * B(j1)) Next j1 If LINK = 1 Then aux = Exp(-z) pdf = aux / (1 + aux) ^ 2 cdf = 1 / (1 + aux) Else pdf = Exp(-z * z / 2) * pi cdf = Application.NormSDist(z) End If a1 = pdf / cdf a2 = pdf / (1 - cdf) For j1 = 1 To k For k1 = j1 To k MCOV(j1, k1) = MCOV(j1, k1) + ((XY( i3, j1) * a1 * a2 * XY(i3, k1)) * PES(i3)) Next k1 MCOV(j1, k + 1) = MCOV(j1, k + 1) + ((( Y * a1 - (1 - Y) * a2) * XY(i3, j1)) * PES(i3)) Next j1 lh(1) = lh(1) + (((Y * Log(cdf)) + ((1 - Y) * Log(1 - cdf))) * PES(i3)) Next i3 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 MCOV(k1, j1) = MCOV(j1, k1) Next k1 If j1 < k + 1 Then d_g(j1) = MCOV(j1, k + 1 ) Next j1 Call C_G2SWEEP(1, IC, MCOV, N, k + 1, 0.0000000 1, False) For j1 = 1 To k B(j1) = B(j1) + MCOV(j1, k + 1) d_g(k + j1) = MCOV(j1, k + 1) Next j1 c = Application.max(Abs(lh(2) - lh(1)), Applica tion.SumSq(d_g)) lh(2) = lh(1) If c <= CONVERG Then avis = True Exit For End If Next it it = it - 1 If NPES = 0 Then yuns = Application.Sum(R_XY.Column s(NY)) Else yuns = Application.SumProduct(R_XY.Colu mns(NY), R_XY.Columns(NPES)) / NTPESM lh(0) = IIf(IC = 1, yuns * Log(yuns / NTPES) + (NTP ES - yuns) * Log((NTPES - yuns) / NTPES), NTPES * L og(0.5)) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' 'Càlculs intermigs: taula classificació i/o contras tos generalitzats' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' If OPT(4) Or OPT(9) Then If OPT(4) Then Dim dim1 As Integer

Page 118: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

117

dim1 = Application.max(3, k + 1 - IC) ReDim E(1 To 4) As Double, maux(1 To dim1, 1 To dim1, 1 To 4), xy_(1 To dim1) As Double End If If OPT(9) Then ReDim aux1(1 To k) As Double, i(1 To 51, 1 To 10), b1(1 To k) As Double For j1 = 1 To 51 i(j1, 10) = 0 + (j1 - 1) * 0.02 Next j1 End If For i3 = 1 To N Y = XY(i3, k + 1) z = 0 For j1 = 1 To k z = z + (XY(i3, j1) * (B(j1))) Next j1 cdf = IIf(LINK = 1, 1 / (1 + Exp(-z)), Appli cation.NormSDist(z)) If OPT(4) Then pdf = Exp(-z * z / 2) * pi E(1) = -((1 - Y) * (pdf / (1 - cdf))) + ( Y * (pdf / cdf)) E(2) = -z * E(1) E(3) = (2 + (z ^ 2)) * E(1) E(4) = -((3 * z) + (z ^ 3)) * E(1) For i2 = 1 To 4 If i2 < 3 Then dim1 = 2 xy_(1) = E(i2 + 2) ElseIf i2 = 3 Then dim1 = 3# xy_(1) = E(3) xy_(2) = E(4) Else dim1 = k + 1 - IC For j1 = IC + 1 To k xy_(j1 - IC) = E(2) * XY(i3, j 1) Next j1 End If xy_(dim1) = 1 For j1 = 1 To dim1 For k1 = j1 To dim1 maux(j1, k1, i2) = maux(j1, k 1, i2) + (xy_(j1) * xy_(k1)) Next k1 Next j1 Next i2 End If If OPT(9) Then aux = 0 For j1 = 1 To k aux1(j1) = 0 For k1 = 1 To k aux = aux + (XY(i3, j1) * MCOV(j1 , k1) * XY(i3, k1)) aux1(j1) = aux1(j1) + (MCOV(j1, k 1) * XY(i3, k1)) Next k1 Next j1 aux = IIf(Y = 1, 1 - cdf, -cdf) / (1 - (( 1 - cdf) * cdf * aux)) For j1 = 1 To k b1(j1) = B(j1) - (aux1(j1) * aux * PE S(i3)) Next j1 z = 0 For j1 = 1 To k z = z + (XY(i3, j1) * (b1(j1))) Next j1 cdf = IIf(LINK = 1, 1 / (1 + Exp(-z)), Ap plication.NormSDist(z)) For j1 = 1 To 51 If XY(i3, k + 1) = 1 And cdf >= i(j1, 10) Then i(j1, 1) = i(j1, 1) + 1 ElseIf XY(i3, k + 1) = 0 And cdf >= i (j1, 10) Then i(j1, 3) = i(j1, 3) + 1 End If Next j1 End If Next i3 End If End Sub Private Sub M3_01(avis, it, lh, yuns) '''''''''''''''''''''''''''''''''''''''''''' 'Escriptura de la informació de l'estimació' '''''''''''''''''''''''''''''''''''''''''''' Dim c As Integer, y1 As Double y1 = Application.Sum(R_XY.Columns(NY))

Page 119: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

118

If avis Then c = 0 Else c = 1 ReDim R(1 To 9 + IIf(NPES <> 0, 3, 0), 1 To 3 + c) R(1, 1) = "Modelo de probabilidad" R(1, 3 + c) = IIf(LINK = 1, "LOGIT", "PROBIT") R(2, 1) = "Técnica de optimización" R(2, 3 + c) = "''Scoring' (Fisher)" R(3, 1) = "Variable cualitativa" R(3, 3 + c) = LVAR(k + 1, 2) If NPES <> 0 Then R(4, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 0)" R(4, 3 + c) = NTPES - y1 R(5, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 0) pond." R(5, 3 + c) = NTPES - yuns R(6, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 1)" R(6, 3 + c) = y1 R(7, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 1) pond." R(7, 3 + c) = yuns R(12, 1) = "Variable de ponderación" R(12, 3 + c) = LVAR(NPES, 1) Else R(4, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 0)" R(4, 3 + c) = NTPES - yuns R(5, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 1)" R(5, 3 + c) = yuns End If R(6 + IIf(NPES <> 0, 2, 0), 1) = "Observaciones tot ales" R(6 + IIf(NPES <> 0, 2, 0), 3 + c) = NTPES R(7 + IIf(NPES <> 0, 2, 0), 1) = "Iteraciones efect uadas" R(7 + IIf(NPES <> 0, 2, 0), 3 + c) = it R(8 + IIf(NPES <> 0, 2, 0), 1) = "Criterio de conve rgencia" R(8 + IIf(NPES <> 0, 2, 0), 3 + c) = CONVERG & IIf( avis, "", " No alcanzado!!!") R(9 + IIf(NPES <> 0, 2, 0), 1) = "Log. L" R(9 + IIf(NPES <> 0, 2, 0), 3 + c) = lh(1) Call M3_ESCRIPTURA(1, "Información general de la es timación", False) End Sub Private Sub M3_02(lh) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' 'Escriptura dels criteris d'informació de l'ajustam ent' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' ReDim aux(1 To 2) As String, R(1 To 6, 1 To 3) aux(1) = IIf(IC = 1, "Sólo" & Chr(10) & "Constante" , "Sin" & Chr(10) & "parámetros") aux(2) = "Con todos los" & Chr(10) & "parámetros" R(1, 1) = "Criterio" R(1, 2) = aux(1) R(1, 3) = aux(2) R(3, 1) = "AIC" R(4, 1) = "Schwarz" R(5, 1) = "-2 log L" R(3, 2) = -2 * lh(0) + 2 * IC R(4, 2) = -2 * lh(0) + Log(NTPES) * IC R(5, 2) = -2 * lh(0) R(3, 3) = -2 * lh(1) + 2 * k R(4, 3) = -2 * lh(1) + Log(NTPES) * k R(5, 3) = -2 * lh(1) R(6, 1) = "pseudo-R" & Chr(178) R(6, 2) = 1 - (lh(1) / lh(0)) Call M3_ESCRIPTURA(2, "Criterios de información del ajuste", False) End Sub Private Sub M3_03(avis, lh, yuns) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' 'Càlcul i escriptura del test Raó de Versemblança, Score i Wald' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' Dim auxm() As Double, i3 As Integer, j1 As Integer, k1 As Integer, test(1 To 3) As Double, vto As Doub le test(1) = -2 * (lh(0) - lh(1)) ReDim auxm(1 To k + 1, 1 To k + 1), xy_(1 To k + 1) As Double For i3 = 1 To N For j1 = 1 To k xy_(j1) = XY(i3, j1) Next j1 xy_(k + 1) = XY(i3, k + 1) - IIf(IC = 1, (yuns / NTPES), 0.5) For j1 = 1 To k + 1 For k1 = j1 To k + 1

Page 120: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

119

auxm(j1, k1) = auxm(j1, k1) + (xy_(j1) * xy_(k1) * PES(i3)) Next k1 Next j1 Next i3 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 auxm(k1, j1) = auxm(j1, k1) Next k1 Next j1 vto = auxm(k + 1, k + 1) Call C_G2SWEEP(1, IC, auxm, N, k + 1, 0.00000001, F alse) test(2) = N * (vto - auxm(k + 1, k + 1)) / vto ReDim auxm(1 To k - IC + 1, 1 To k - IC + 1) For k1 = 1 To k - IC For j1 = 1 To k - IC auxm(k1, j1) = MCOV(k1 + IC, j1 + IC) Next j1 Next k1 Call C_G2SWEEP(1, IC, auxm, N, k - IC + 1, 0.000000 01, False) For k1 = 1 To k - IC For j1 = 1 To k - IC test(3) = test(3) + (B(k1 + IC) * auxm(k1, j1) * B(j1 + IC)) Next j1 Next k1 ReDim R(1 To 4, 1 To 4) R(1, 1) = "Test" R(1, 2) = "Valor c" & Chr(178) R(1, 3) = "gl" R(1, 4) = "Prob > c" & Chr(178) R(2, 1) = "Rat. verosim." R(3, 1) = "''Score'" R(4, 1) = "Wald" For j1 = 1 To 3 R(j1 + 1, 2) = test(j1) R(j1 + 1, 3) = k - IC R(j1 + 1, 4) = Application.ChiDist(test(j1), k - IC) R(j1 + 1, 4) = IIf(R(j1 + 1, 4) < 0.0001, "< 0. 0001", R(j1 + 1, 4)) Next j1 avis = True If OPT(4) Then avis = False If OPT(5) Then avis = False If UBound(MCOV, 1) <= 12 Then avis = False Call M3_ESCRIPTURA(3, "Hipótesis nula: Pendiente" & IIf(k = 1, "", "(s)") & "=0", avis) End Sub Private Sub M3_04(avis, maux) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' 'Càlculs i escriptura dels tests basats en residus generalitzats' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' Dim dim1 As Integer, i1 As Integer, j1 As Integer, k1 As Integer dim1 = Application.max(3, k + 1 - IC) ReDim m(1 To dim1, 1 To dim1) As Double, R(1 To 5, 1 To 5), tests(1 To 4) R(1, 1) = "Hipótesis nula" R(1, 3) = "Valor c" & Chr(178) R(1, 4) = "gl" R(1, 5) = "Prob > c" & Chr(178) R(2, 1) = "Simetría" R(3, 1) = "Apuntamiento=0" R(4, 1) = "Normalidad" R(5, 1) = "Homoscedasticidad" For i1 = 1 To 4 If i1 < 3 Then dim1 = 2 ElseIf i1 = 3 Then dim1 = 3 Else dim1 = k + 1 - IC End If For j1 = 1 To dim1 For k1 = j1 + 1 To dim1 maux(k1, j1, i1) = maux(j1, k1, i1) Next k1 Next j1 For j1 = 1 To dim1 For k1 = 1 To dim1 m(j1, k1) = maux(j1, k1, i1) Next k1

Page 121: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

120

Next j1 Call C_G2SWEEP(1, IC, m, N, dim1, 0.00000001, F alse) tests(i1) = N - m(dim1, dim1) R(i1 + 1, 3) = tests(i1) R(i1 + 1, 4) = dim1 - 1 R(i1 + 1, 5) = Application.ChiDist(R(i1 + 1, 3) , R(i1 + 1, 4)) R(i1 + 1, 5) = IIf(R(i1 + 1, 5) < 0.0001, "< 0. 0001", R(i1 + 1, 5)) Next i1 avis = True If OPT(5) Then avis = False If UBound(MCOV, 1) <= 12 Then avis = False Call M3_ESCRIPTURA(4, "Contrastes basados en residu os generalizados ", avis) End Sub Private Sub M3_05(avis) '''''''''''''''''''''' 'Restriccions lineals' '''''''''''''''''''''' Dim aux(1 To 2) As Double, a1() As Double, a2() As Double, a3() As Double, a4() As Boolean, _ glr() As Integer, irest As Integer, i1 As Integ er, i2 As Integer, n_r() As String, w() As Double Call C_RESTRICCIONES_1(1, MCOV, a1, a2, a3, a4, w, glr, irest, n_r) If SORTIR Then SORTIR = False If irest <= 1 Then Exit Sub Else irest = irest - 1 End If '''''''''''''''''''''''''''''''''''''''''''''''''' 'Calcula l'amplada de columna per a la restricció' '''''''''''''''''''''''''''''''''''''''''''''''''' aux(1) = 0 For i1 = 1 To irest If Len(n_r(i1)) > aux(1) Then i2 = i1 aux(1) = Len(n_r(i1)) End If Next i1 With Cells(1, 11) aux(2) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = n_r(i2) .Columns.AutoFit aux(1) = .ColumnWidth .Clear .ColumnWidth = aux(2) End With For i1 = 6 To 1 Step -1 If aux(1) > i1 * 9.57 Then Exit For Next i1 aux(2) = Application.max(i1 + 1, 1) ReDim R(1 To irest + 1, 1 To aux(2) + 3) R(1, 1) = "Restricción" R(1, aux(2) + 1) = "Valor c" & Chr(178) R(1, aux(2) + 2) = "gl" R(1, aux(2) + 3) = "Prob > c" & Chr(178) For i1 = 1 To irest R(i1 + 1, 1) = n_r(i1) R(i1 + 1, aux(2) + 1) = w(i1) R(i1 + 1, aux(2) + 2) = glr(i1) R(i1 + 1, aux(2) + 3) = Application.ChiDist(w(i 1), glr(i1)) R(i1 + 1, aux(2) + 3) = IIf(R(i1 + 1, aux(2) + 3) < 0.0001, "< 0.0001", R(i1 + 1, aux(2) + 3)) Next i1 If UBound(MCOV, 1) <= 12 Then avis = False Else avi s = True Call M3_ESCRIPTURA(5, "Restricciones lineales (Test de Wald)", avis) End Sub Private Sub M3_06(avis) ''''''''''''''''''''''''''' 'Escriptura de l'estimació' ''''''''''''''''''''''''''' Dim aux As Double, i1 As Integer ReDim R(1 To k + 2, 1 To IIf(LINK = 1, 10, 7)) R(1, 1) = "Variable"

Page 122: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

121

R(1, 2) = "Parámetro" R(1, 3) = "Error" & Chr(10) & "Estándar" R(1, 4) = "Valor c" & Chr(178) R(1, 5) = "Prob > c" & Chr(178) R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" If SIG = 0.01 Then aux = 2.575834515 ElseIf SIG = 0.05 Then aux = 1.959961082 ElseIf SIG = 0.1 Then aux = 1.644853 ElseIf SIG = 0.15 Then aux = 1.439530024 ElseIf SIG = 0.2 Then aux = 1.281550794 ElseIf SIG = 0.25 Then aux = 1.150349362 End If For i1 = 1 To k R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & " )" R(i1 + 2, 2) = B(i1) R(i1 + 2, 3) = Sqr(MCOV(i1, i1)) R(i1 + 2, 4) = (R(i1 + 2, 2) / R(i1 + 2, 3)) ^ 2 R(i1 + 2, 5) = Application.ChiDist(R(i1 + 2, 4) , 1) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0. 0001", R(i1 + 2, 5)) R(i1 + 2, 6) = B(i1) - (aux * R(i1 + 2, 3)) R(i1 + 2, 7) = B(i1) + (aux * R(i1 + 2, 3)) Next i1 If LINK = 1 Then R(1, 8) = "''Odds' Ratios" R(1, 9) = "Intervalo 'Odds' Ratios" & Chr(10) & "(sig.=" & Format(SIG, "0.00") & ")" For i1 = IC + 1 To k R(i1 + 2, 8) = Exp(B(i1)) R(i1 + 2, 9) = Exp(R(i1 + 2, 6)) R(i1 + 2, 10) = Exp(R(i1 + 2, 7)) Next i1 End If If k <= 36 Then avis = False Else avis = True Call M3_ESCRIPTURA(6, "Resultados de la estimación" , avis) End Sub Private Sub M3_08(opcio As Integer) '''''''''''''''''''''''''''''''''''''' 'Prediccions i intervals de predicció' '''''''''''''''''''''''''''''''''''''' With C2_Varis .Caption = "Modelos Logit y Probit: Predicción" .Frame7.Height = 65 With .MultiPage1 .Height = 75 .Style = fmTabStyleNone .Value = 6 End With .Height = 95 End With Application.ScreenUpdating = True 'Això està bé aq uí ERR_LEC = True Do While ERR_LEC = True C2_Varis.Show If SORTIR Then ERR_LEC = False Loop Application.ScreenUpdating = False 'Això està bé aq uí Unload C2_Varis If SORTIR Then SORTIR = False Exit Sub End If Dim np As Integer, ip As Boolean np = UBound(XYp, 1) If UBound(XYp, 2) > k Then ip = True Dim aux(1 To 2), llarg_p, i1 As Integer, j1 As Inte ger, k1 As Integer, l1 As Integer, _ s As Double, z As Double ReDim X(1 To k) As Double, cdf(1 To np, 1 To 3) As Double ''''''''''''''''''''''''''''''''''''''''''''''''''' '

Page 123: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

122

'Determina l'amplada de columna dels identificadors ' ''''''''''''''''''''''''''''''''''''''''''''''''''' ' aux(1) = 0 aux(2) = 0 llarg_p = 1 If ip Then For i1 = 1 To np aux(2) = XYp(i1, UBound(XYp, 2)) If Len(aux(2)) > aux(1) Then aux(1) = Len(aux(2)) llarg_p = i1 End If Next i1 With Cells(1, 11) aux(1) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = XYp(llarg_p, UBound(XYp, 2)) .Columns.AutoFit aux(2) = .ColumnWidth .Clear .ColumnWidth = aux(1) End With If aux(2) > 9.57 Then llarg_p = 2 End If l1 = llarg_p If SIG = 0.01 Then aux(1) = 2.575834515 ElseIf SIG = 0.05 Then aux(1) = 1.959961082 ElseIf SIG = 0.1 Then aux(1) = 1.644853 ElseIf SIG = 0.15 Then aux(1) = 1.439530024 ElseIf SIG = 0.2 Then aux(1) = 1.281550794 ElseIf SIG = 0.25 Then aux(1) = 1.150349362 End If For i1 = 1 To np For j1 = 1 To k X(j1) = XYp(i1, j1) Next j1 z = 0 For j1 = 1 To k z = z + (X(j1) * B(j1)) Next j1 s = 0 For j1 = 1 To k For k1 = 1 To k s = s + (X(j1) * MCOV(j1, k1) * X(k1)) Next k1 Next j1 s = Sqr(s) * aux(1) cdf(i1, 1) = IIf(LINK = 1, 1 / (1 + Exp(-z)), A pplication.NormSDist(z)) cdf(i1, 2) = IIf(LINK = 1, 1 / (1 + Exp(-(z - s ))), Application.NormSDist(z - s)) cdf(i1, 3) = IIf(LINK = 1, 1 / (1 + Exp(-(z + s ))), Application.NormSDist(z + s)) Next i1 Dim dim1 As Integer, i2 As Integer, maxim1 As Integ er, resta1 As Integer dim1 = IIf(np <= 68, np, 68) maxim1 = IIf(np <= 68, 1, Int(np / 68)) resta1 = IIf(np <= 68, 0, np - (maxim1 * 68)) If resta1 <> 0 Then maxim1 = maxim1 + 1 For i2 = 1 To maxim1 ReDim R(1 To IIf(i2 < maxim1, dim1 + 2, IIf(i2 = 1, dim1, IIf(resta1 <> 0, resta1, dim1)) + 2), 1 To 3 + l1) R(1, 1) = "Observación" R(1, 1 + l1) = "Predicción" & Chr(10) & "puntua l" R(1, 2 + l1) = "Intervalo Predicción" & Chr(10) & "(sig.=" & Format(SIG, "0.00") & ")" For i1 = 1 To IIf(i2 < maxim1, dim1, IIf(i2 = 1 , dim1, IIf(resta1 <> 0, resta1, dim1))) j1 = i1 + ((i2 - 1) * 68) If ip Then R(i1 + 2, 1) = XYp(j1, UBound(XY p, 2)) Else R(i1 + 2, 1) = Str(j1) R(i1 + 2, 1 + l1) = cdf(j1, 1) R(i1 + 2, 2 + l1) = cdf(j1, 2) R(i1 + 2, 3 + l1) = cdf(j1, 3) Next i1 Call M3_ESCRIPTURA(7, "Predicciones puntuales y por intervalo p(y=1)" & IIf(i2 = 1, "", " (cont.)" ), True)

Page 124: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

123

Next i2 End Sub Private Sub M3_09(i, yuns) '''''''''''''''''''''''''''''''''''''''''''''''''' 'Càlcul i escriptura de la taula de classificació' '''''''''''''''''''''''''''''''''''''''''''''''''' yuns = Application.Sum(R_XY.Columns(NY)) Dim i_f As Integer, i_i As Integer, i1 As Integer, j1 As Integer 'For i1 = 1 To 51 ' If i(i1, 1) = yuns And i(i1, 3) = N - yuns The n i_i = i1 Else Exit For 'Next i1 'For i1 = 51 To i_i Step -1 ' If i(i1, 1) = 0 And i(i1, 3) = 0 Then i_f = i1 Else Exit For 'Next i1 'For i1 = i_i To i_f For i1 = 1 To 51 i(i1, 2) = N - yuns - i(i1, 3) i(i1, 4) = yuns - i(i1, 1) For j1 = 1 To 4 If i(i1, j1) = "" Then i(i1, j1) = 0 Next j1 i(i1, 5) = (i(i1, 1) + i(i1, 2)) / N i(i1, 6) = i(i1, 1) / yuns i(i1, 7) = i(i1, 2) / (N - yuns) If i(i1, 1) + i(i1, 3) <> 0 Then i(i1, 8) = i(i 1, 3) / (i(i1, 1) + i(i1, 3)) If i(i1, 2) + i(i1, 4) <> 0 Then i(i1, 9) = i(i 1, 4) / (i(i1, 2) + i(i1, 4)) Next i1 'ReDim R(1 To i_f - i_i + 3, 1 To 10) ReDim R(1 To 53, 1 To 10) R(1, 1) = "Probabilidad" R(1, 2) = "Predicciones correctas" R(1, 4) = "Predicciones incorrectas" R(2, 2) = "Y=1" R(2, 3) = "Y=0" R(2, 4) = "Y=1" R(2, 5) = "Y=0" R(1, 7) = "RATIOS" R(2, 6) = "Aciertos" R(2, 7) = "''Sensibilidad'" R(2, 8) = "''Especificidad'" R(2, 9) = "Falsos (+)" R(2, 10) = "Falsos (-)" 'For i1 = 1 To i_f - i_i + 1 For i1 = 1 To 51 ' R(i1 + 2, 1) = i(i1 + i_i - 1, 10) R(i1 + 2, 1) = i(i1, 10) For j1 = 1 To 9 ' R(i1 + 2, j1 + 1) = i(i1 + i_i - 1, j1) R(i1 + 2, j1 + 1) = i(i1, j1) Next j1 Next i1 Call M3_ESCRIPTURA(8, "Tabla de clasificación de pr edicciones", True) End Sub Private Sub M3_09_1(yuns) ''''''''''''' 'CURVA 'ROC'' ''''''''''''' Dim area As Double, cdf As Double, i(1 To 51, 1 To 5) As Double, i_f As Integer, i_i As Integer, i1 As Integer, _ j1 As Integer, ncells As Integer, RG As Range, titol1 As String, z As Double For i1 = 1 To 51 i(i1, 5) = 0 + (i1 - 1) * 0.02 Next i1 For i1 = 1 To N z = 0 For j1 = 1 To k z = z + (XY(i1, j1) * (B(j1))) Next j1 cdf = IIf(LINK = 1, 1 / (1 + Exp(-z)), Applicat ion.NormSDist(z)) For j1 = 1 To 51 If XY(i1, k + 1) = 1 And cdf >= i(j1, 5) Th en i(j1, 1) = i(j1, 1) + 1 ElseIf XY(i1, k + 1) = 0 And cdf >= i(j1, 5 ) Then i(j1, 3) = i(j1, 3) + 1

Page 125: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

124

End If Next j1 Next i1 For i1 = 1 To 51 i(i1, 2) = N - yuns - i(i1, 3) i(i1, 4) = yuns - i(i1, 1) Next i1 ReDim yx_(1 To 51, 1 To 2) As Double For i1 = 1 To 51 yx_(i1, 1) = i(i1, 1) / yuns yx_(i1, 2) = 1 - (i(i1, 2) / (N - yuns)) Next i1 area = 0 For i1 = 1 To UBound(yx_, 1) - 1 area = area + 0.5 * (yx_(i1 + 1, 1) + yx_(i1, 1 )) * (yx_(i1 + 1, 2) - yx_(i1, 2)) Next i1 Sheets(FULL_R).Activate ncells = 52 Set RG = Range(Cells(F - 2, 1), Cells(F - 2 + ncell s, 10)) With RG .ColumnWidth = 9.5 .Font.Name = "Arial" .Font.Size = 7 .HorizontalAlignment = xlCenter .Interior.ColorIndex = 2 .NumberFormat = "0.0000" .RowHeight = 11 End With For i1 = 1 To 51 RG.Rows(i1 + 2).Columns(1) = i(i1, 5) For j1 = 1 To 2 RG.Rows(i1 + 2).Columns(j1 + 1) = yx_(i1, j 1) Next j1 Next i1 With RG.Rows(2) .Columns(1).Value = "Probabilidad" .Columns(2).Value = "Sensibilidad" .Columns(3).Value = "____________ Especificidad" .Font.Bold = True .RowHeight = 15 .WrapText = True End With Set RG = Range(Cells(F, 2), Cells(F + ncells, 3)) titol1 = " __________ " & _ Chr(10) & "Curva ROC (Sensibilidad vs. Esp ecificidad)" Charts.Add With ActiveChart .ChartType = xlXYScatter .SeriesCollection.NewSeries With .SeriesCollection(1) .MarkerBackgroundColorIndex = 3 .MarkerForegroundColorIndex = 3 .MarkerSize = 5 .MarkerStyle = xlNone .Shadow = False .Smooth = True .Values = RG.Columns(1) .XValues = RG.Columns(2) .Border.ColorIndex = 3 .Border.Weight = xlMedium .Border.LineStyle = xlContinuous End With .SeriesCollection.NewSeries With .SeriesCollection(2) .Border.ColorIndex = 1 .Border.LineStyle = xlContinuous .Border.Weight = xlMedium .MarkerStyle = xlNone .Values = Array(0, 1) .XValues = Array(0, 1) End With With .Axes(xlCategory) .HasMajorGridlines = False .HasMinorGridlines = False .MinimumScale = 0 .MaximumScale = 1 .MinorUnit = 0.1 .MajorUnit = 0.1

Page 126: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

125

.TickLabels.AutoScaleFont = False .TickLabels.Font.Size = 8 .TickLabels.NumberFormat = "0.0" End With With .Axes(xlValue) .HasMajorGridlines = False .HasMinorGridlines = False .MinimumScale = 0 .MaximumScale = 1 .MinorUnit = 0.1 .MajorUnit = 0.1 .TickLabels.AutoScaleFont = False .TickLabels.Font.Size = 8 .TickLabels.NumberFormat = "0.0" End With With .PlotArea .Border.Weight = xlThin .Border.LineStyle = xlContinuous .Interior.ColorIndex = 2 .Interior.PatternColorIndex = 1 .Interior.Pattern = xlSolid End With .HasLegend = False .HasTitle = True With .ChartTitle .AutoScaleFont = False .Characters.Text = titol1 .Font.Size = 10 .Font.Bold = True .Top = 1 End With With .Axes(xlCategory, xlPrimary) .HasTitle = True With .AxisTitle .Characters.Text = "Área por debajo de la cur va = " & Format(-area, "0.000") .Font.Size = 8 .Left = 450 .Top = 360 End With End With .Location Where:=xlLocationAsObject, Name:=FULL_R End With '''''''''''''''''''''''''''''''''''''''''''' 'Posicionament, amplada i alçada del gràfic' '''''''''''''''''''''''''''''''''''''''''''' With Worksheets(FULL_R) .ChartObjects(1).Height = 325 .ChartObjects(1).Width = 375 End With ''''''''''''''''''''''''''''''''''''''''''''''''' 'Enxampla el gràfic a la dimensió de la finestra' ''''''''''''''''''''''''''''''''''''''''''''''''' With ActiveChart With .PlotArea .Top = 30 .Height = 310 .Left = 1 .Width = 500 End With End With ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' 'Reconversió dels gràfics en imatges i eliminació d els gràfics' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''' ActiveSheet.ChartObjects(1).CopyPicture Cells(F + 10, 4).Select ActiveSheet.Paste Worksheets(FULL_R).ChartObjects(1).Delete ActiveWindow.SelectedSheets.HPageBreaks.Add (Cells( F + ncells - 1, 1)) F = F + ncells Cells(1, 1).Select Sheets(FULL).Activate End Sub Private Sub M3_ESCRIPTURA(opcio As Integer, TITOL A s String, avis)

Page 127: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

126

'''''''''''''''''''' 'Escriptura general' '''''''''''''''''''' Sheets(FULL_R).Activate ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' 'opcio=1 ==> Informació general de l'estimació ' 'opcio=2 ==> Criteris d'informació de l'ajustament ' 'opcio=3 ==> Test Raó de Versemblança, Multiplicado rs de Lagrange i Wald' 'opcio=4 ==> Tests basats en residus generalitzats ' 'opcio=5 ==> Restriccions lineals ' 'opcio=6 ==> Estimació ' 'opcio=7 ==> Matriu de variàncies i covariàncies ' 'opcio=8 ==> Prediccions i intervals de predicció ' 'opcio=9 ==> Taula de classificació ' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' Dim c(1 To 2) As Integer, i1 As Integer, j1 As Inte ger, k1 As Integer, m1 As Double, m2 As Double c(1) = UBound(R, 1) c(2) = UBound(R, 2) With Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 10) ) .ColumnWidth = 9.5 With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter .Interior.ColorIndex = 2 .RowHeight = 11 .VerticalAlignment = xlCenter End With With Cells(F - 1, 1) .Font.Bold = True .HorizontalAlignment = xlLeft .Value = TITOL End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) .Borders(xlEdgeTop).LineStyle = xlDouble .Borders(xlEdgeBottom).LineStyle = xlDouble .Interior.ColorIndex = 37 .Value = R End With With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Font.Bold = True .HorizontalAlignment = xlLeft End With If opcio <> 1 And opcio <> 8 Then i1 = IIf(opcio = 2 Or opcio = 6 Or opcio = 7, 1, 0) For j1 = 1 To c(2) With Range(Cells(F, j1), Cells(F + i1, j1)) .Borders(xlEdgeBottom).LineStyle = xlConti nuous .Font.Bold = True .MergeCells = True .WrapText = True End With Next j1 End If If opcio = 1 Then 'Quadre informació general For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , 2)).MergeCells = True If c(2) = 4 Then Range(Cells(F + i1 - 1, 3), Cells(F + i1 - 1, 4)).MergeCells = True With Cells(F + i1 - 1, 3) .HorizontalAlignment = xlRight If i1 >= 4 And i1 <= IIf(NPES <> 0, 9, 7) Then .NumberFormat = "###,0" If i1 = IIf(NPES <> 0, 10, 8) Then .Number Format = "0.00E+00" If i1 = IIf(NPES <> 0, 11, 9) Then If Abs(R(i1, 3)) >= 1000 And Abs(R(i1, 3)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, 3)) < 1000 And Abs(R(i1, 3 )) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End If End With Next i1 ElseIf opcio = 2 Then 'Quadre criteris informació ajustament For i1 = 3 To c(1) ' - IIf(IC = 1, 2, 1) For j1 = 2 To c(2) With Cells(F + i1 - 1, j1) If R(i1, j1) >= 1000 And R(i1, j1) < 1 0 ^ 9 Then .NumberFormat = "###,0.000" If R(i1, j1) < 1000 And R(i1, j1) >= 1 0 ^ (-6) Then .NumberFormat = "##0.000000" End With Next j1

Page 128: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

127

Next i1 Cells(F + c(1) - 1, 2).NumberFormat = "0.0000" Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeTop).LineStyle = xlContinuou s Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , 2)).VerticalAlignment = xlCenter ElseIf opcio = 3 Or opcio = 4 Or opcio = 5 Then '3 =Pendents 0,4=Tests Generalitzats, 5=Restriccions For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , c(2) - 3)).MergeCells = True Next i1 If opcio = 5 Then For i1 = 2 To c(1) With Cells(F + i1 - 1, 1) For j1 = 1 To Len(R(i1, 1)) If Mid(R(i1, 1), j1, 1) = "b" Then .Characters(j1, 1).Font.Name = " Symbol" .Font.Bold = True End If Next j1 End With Next i1 End If Cells(F, c(2) - 2).Characters(8, 1).Font.Name = "symbol" Cells(F, c(2) - 2).Characters(8, 1).Font.Bold = True Cells(F, c(2)).Characters(8, 1).Font.Name = "sym bol" Cells(F, c(2)).Characters(8, 1).Font.Bold = True For i1 = 2 To c(1) For j1 = c(2) - 2 To c(2) With Cells(F + i1 - 1, j1) If j1 = c(2) - 2 Then .NumberFormat = "###,0.000" If j1 = c(2) - 1 Then .NumberFormat = "0" If j1 = c(2) Then .NumberFormat = "0.0 000" End With Next j1 Next i1 ElseIf opcio = 6 Then 'Quadre Estimació Range(Cells(F, 6), Cells(F + 1, 7)).MergeCells = True Range(Cells(F, 9), Cells(F + 1, 10)).MergeCells = True Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1) .Font.Name = "symbol" Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1) .Font.Bold = True Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Name = "symbol" Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Bold = True Range(Cells(F + 2, 4), Cells(F + c(1) - 1, 4)).N umberFormat = "###,0.000" Range(Cells(F + 2, 5), Cells(F + c(1) - 1, 5)).N umberFormat = "0.0000" For i1 = 2 To c(1) For j1 = 2 To 7 + IIf(LINK = 1, 3, 0) If j1 = 2 Or j1 = 3 Or j1 = 6 Or j1 = 7 Or j1 = 8 Or j1 = 9 Or j1 = 10 Then With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R (i1, j1)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, j1)) < 1000 And Abs(R( i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000 000" End With End If Next j1 Next i1 ElseIf opcio = 7 Then 'Prediccions j1 = IIf(c(2) = 4, 1, 2) With Range(Cells(F, 1), Cells(F + 1, j1)) .HorizontalAlignment = xlCenter .MergeCells = True End With Range(Cells(F, j1 + 1), Cells(F + 1, j1 + 1)).Me rgeCells = True Range(Cells(F, c(2) - 1), Cells(F + 1, c(2))).Me rgeCells = True If j1 = 2 Then For i1 = 2 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1, 2)).MergeCells = True Next i1 End If Range(Cells(F + 2, c(2) - 2), Cells(F + 2 + c(1) , c(2))).NumberFormat = "0.0000" ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) ElseIf opcio = 8 Then 'Taula de classificació With Range(Cells(F, 1), Cells(F + 1, c(2))) .Borders(xlEdgeBottom).LineStyle = xlContinuou s .Font.Bold = True End With Range(Cells(F, 1), Cells(F + 1, 1)).MergeCells = True For j1 = 2 To 4 Step 2 With Range(Cells(F, j1), Cells(F, j1 + 1)) .Borders(xlEdgeBottom).LineStyle = xlConti nuous .MergeCells = True End With Next j1

Page 129: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

128

With Range(Cells(F, 7), Cells(F, c(2))) .Borders(xlEdgeBottom).LineStyle = xlContinuou s .MergeCells = True End With With Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)) .HorizontalAlignment = xlCenter .NumberFormat = "0.000" End With Range(Cells(F + 2, 2), Cells(F + c(1) - 1, 5)).N umberFormat = "###,0" Range(Cells(F + 2, 6), Cells(F + c(1) - 1, 6)).N umberFormat = "##0.00%" Range(Cells(F + 2, 7), Cells(F + c(1) - 1, c(2)) ).NumberFormat = "0.000" ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) ElseIf opcio = 9 Then Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Borde rs(xlRight).LineStyle = xlContinuous For i1 = 2 To c(1) Cells(F + i1 - 1, 1).Characters(1, 1).Font.N ame = "symbol" Cells(F + i1 - 1, 1).Characters(1, 1).Font.B old = True Cells(F, i1).Characters(1, 1).Font.Name = "s ymbol" Cells(F, i1).Characters(1, 1).Font.Bold = Tr ue Next i1 End If If avis Then ActiveWindow.SelectedSheets.HPageBreak s.Add (Cells(F + c(1), 1)) F = F + c(1) + 2 Sheets(FULL).Activate End Sub Private Sub M3_ESCRIPTURA_1(avis) '''''''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A L'ESCRIPTURA DE MATRIUS' '''''''''''''''''''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, j1 As Integer, j2 As Integer Dim dim1 As Integer, dim2 As Integer, maxim2 As Int eger, resta2 As Integer dim1 = UBound(MCOV, 1) - 1 dim2 = IIf(dim1 <= 9, dim1, 9) maxim2 = IIf(dim1 <= 9, 1, Int(dim1 / 9)) resta2 = IIf(dim1 <= 9, 0, dim1 - (maxim2 * 9)) If resta2 <> 0 Then maxim2 = maxim2 + 1 avis = False For j1 = 1 To maxim2 ReDim R(1 To dim1 + 1, 1 To IIf(j1 < maxim2, di m2, IIf(j1 = 1, dim2, IIf(resta2 <> 0, resta2, dim2 ))) + 1) For j2 = 1 To IIf(j1 < maxim2, dim2, IIf(j1 = 1 , dim2, IIf(resta2 <> 0, resta2, dim2))) i2 = j2 + ((j1 - 1) * 9) R(1, j2 + 1) = "b" & i2 & "(" & LVAR(i2, 2) & ")" Next j2 For i1 = 1 To dim1 R(i1 + 1, 1) = "b" & i1 & "(" & LVAR(i1, 2) & ")" For j2 = 1 To IIf(j1 < maxim2, dim2, IIf(j1 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) R(i1 + 1, j2 + 1) = MCOV(i1, j2 + ((j1 - 1) * 9)) Next j2 Next i1 If dim1 <= 9 Then avis = True ElseIf dim1 <= 18 Then avis = IIf(j1 = 2, True, False) ElseIf dim1 <= 27 Then avis = IIf(j1 = 1 Or j1 = 3, True, False) ElseIf dim1 <= 36 Then avis = IIf(j1 = 2, False, True) Else avis = True End If Call M3_ESCRIPTURA(9, "Matriz de varianzas y co varianzas" & IIf(j1 = 1, "", "(cont.)"), avis) Next j1 End Sub

Page 130: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

129

Attribute VB_Name = "M4_TobitHeckman" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVISEXOGENES As Boolean Private Sub Aceptar_Click() ''''''''''''''''''''''' 'MÓDULO TOBIT y HECKMAN ''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, i3 As Long, j1 As Integer, k1 As Integer, resposta As String ERR_LEC = True 'TOBIT y HECKMAN 1a. etapa For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then NY = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide If LINK = 1 Then MsgBox "Debe seleccionar la var iable endógena.", vbCritical, TITOL If LINK = 2 Then MsgBox "Debe seleccionar la var iable endógena de la 1a. etapa.", vbCritical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VX(1 To i2) VX(i2) = i1 NX = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide If LINK = 1 Then MsgBox "Debe seleccionar al men os una variable exógena.", vbCritical, TITOL If LINK = 2 Then MsgBox "Debe seleccionar al men os una variable exógena para la 1a. etapa.", vbCrit ical, TITOL Exit Sub End If NPES = 0 For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 For i1 = 1 To NX If NY = VX(i1) Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox LVAR(NY, 1) & " no p uede ser endógena y exógena.", vbCritical, TITOL If LINK = 2 Then MsgBox LVAR(NY, 1) & " no p uede ser endógena y exógena en la 1a. etapa.", vbCr itical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If NY = NPES Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox LVAR(NY, 1) & " no pu ede ser endógena y factor de elevación.", vbCritica l, TITOL If LINK = 2 Then MsgBox LVAR(NY, 1) & " no pu ede ser endógena en la 1a. etapa y factor de elevac ión.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If NPES = VX(i1) Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox LVAR(VX(i1), 1) & " no puede ser exógena y factor de elevación.", vb Critical, TITOL If LINK = 2 Then MsgBox LVAR(VX(i1), 1) & " no puede ser exógena en la 1a. etapa y factor de elevación.", vbCritical, TITOL Exit Sub

Page 131: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

130

End If Next i1 End If If LINK = 2 Then 'HECKMAN 2a. etapa ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys2.Selected(i1 - 1) Then NY2 = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable endógena de la 2a. etapa.", vbCritical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs2.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VX2(1 To i2) VX2(i2) = i1 NX2 = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar al menos una variabl e exógena en la 2a. etapa.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX2 If NY = VX2(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY2, 1) & " no puede ser endó gena y exógena en la 2a. etapa.", vbCritical, TITOL Exit Sub End If Next i1 For i1 = 1 To NX2 If NY = VX2(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endóg ena en la 1a. etapa y exógena en la 2a. etapa.", vb Critical, TITOL Exit Sub End If Next i1 For i1 = 1 To NX If NY2 = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY2, 1) & " no puede ser endó gena en la 2a. etapa y exógena en la 1a. etapa.", vbCritical, TITOL Exit Sub End If Next i1 If NX2 = NX Then Me.Hide resposta = MsgBox("Ha seleccionado el mismo n úmero de variables exógenas en la 2a. etapa que en la 1a. etapa." & Chr(10) & Chr(10) & _ "En esta circunstancia, pue de existir subidentificación en los parámetros.", vbInformation, TITOL) End If If NPES <> 0 Then If NY2 = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(NY2, 1) & " no puede ser endóg ena en la 2a. etapa y factor de elevación.", vbCrit ical, TITOL Exit Sub End If For i1 = 1 To NX2 If NPES = VX2(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(VX2(i1), 1) & " no puede s er exógena en la 2a. etapa y factor de elevación.", vbCritical, TITOL Exit Sub End If

Page 132: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

131

Next i1 End If End If If Application.Count(R_XY.Columns(NY)) <> N Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox "Algún valor de la varia ble " & LVAR(NY, 1) & " no es numérico.", vbCritica l, TITOL If LINK = 2 Then MsgBox "Algún valor de la varia ble " & LVAR(NY, 1) & ", de la 1a. etapa, no es num érico.", vbCritical, TITOL Exit Sub End If n0 = Application.CountIf(R_XY.Columns(NY), "=0") If n0 = 0 Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox "No hay ningún valor de la variable " & LVAR(NY, 1) & " que sea 0.", vbCrit ical, TITOL If LINK = 2 Then MsgBox "No hay ningún valor de la variable " & LVAR(NY, 1) & ", de la 1a. etapa, q ue sea 0.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If Application.Count(R_XY.Columns(VX(i1))) <> N Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox "Algún valor de la v ariable " & LVAR(VX(i1), 1) & " no es numérico.", vbCritical, TITOL If LINK = 2 Then MsgBox "Algún valor de la v ariable " & LVAR(VX(i1), 1) & ", de la 1a. etapa, n o es numérico.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If Application.Count(R_XY.Columns(NPES)) <> N Or Application.CountIf(R_XY.Columns(NPES), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N PES, 1) & " es negativo, nulo o no numérico.", vbCr itical, TITOL Exit Sub End If End If If LINK = 2 Then If Application.Count(R_XY.Columns(NY2)) <> N The n ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N Y2, 1) & ", de la 2a. etapa, no es numérico.", vbCr itical, TITOL Exit Sub End If If Application.CountIf(R_XY.Columns(NY2), "=0") = 0 Then ERR_LEC = True Me.Hide MsgBox "No hay ningún valor de la variable " & LVAR(NY2, 1) & ", de la 2a. etapa, que sea 0.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX2 If Application.Count(R_XY.Columns(VX2(i1))) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LV AR(VX2(i1), 1) & ", de la 2a. etapa, no es numérico .", vbCritical, TITOL Exit Sub End If Next i1 End If If Constante.Value = True Then IC = 1 Else IC = 0 k = IC + NX ReDim G2SWEEP(1 To k + 1, 1 To k + 1), XY(1 To N, 1 To k + 1), PES(1 To N) If NPES <> 0 Then NTPESM = Application.Average(R_XY.Rows.Columns(N PES)) NTPES = Application.Sum(R_XY.Rows.Columns(NPES)) / NTPESM Else NTPESM = 1 NTPES = N End If For i3 = 1 To N If NPES <> 0 Then PES(i3) = R_XY.Rows(i3).Colum ns(NPES) / NTPESM Else PES(i3) = 1 If IC = 1 Then XY(i3, 1) = 1 For j1 = 1 To NX

Page 133: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

132

XY(i3, IC + j1) = R_XY.Rows(i3).Columns(VX( j1)) Next j1 XY(i3, k + 1) = R_XY.Rows(i3).Columns(NY) If LINK = 2 Then If XY(i3, k + 1) <> 0 Then XY(i3, k + 1) = 1 End If For j1 = 1 To k + 1 For k1 = j1 To k + 1 G2SWEEP(j1, k1) = G2SWEEP(j1, k1) + (XY (i3, j1) * XY(i3, k1) * PES(i3)) Next k1 Next j1 Next i3 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 G2SWEEP(k1, j1) = G2SWEEP(j1, k1) Next k1 Next j1 Call C_G2SWEEP(0, IC, G2SWEEP, N, k + 1, 0.00000001 , ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide If LINK = 1 Then MsgBox "El modelo no es de rang o completo.", vbCritical, TITOL If LINK = 2 Then MsgBox "El modelo de la 1a. eta pa no es de rango completo.", vbCritical, TITOL Exit Sub End If If IC = 1 Then LVAR(1, 2) = "Const." For i1 = 1 To NX LVAR(IC + i1, 2) = LVAR(VX(i1), 1) Next i1 LVAR(k + 1, 2) = LVAR(NY, 1) NTPES = Application.Sum(PES) If LINK = 2 Then K2 = IC + NX2 ReDim LVAR2(1 To K2 + 4), m(1 To K2 + 1, 1 To K2 + 1) As Double, XY2(1 To N, 1 To K2 + 1) For i3 = 1 To N If IC = 1 Then XY2(i3, 1) = 1 For j1 = 1 To NX2 XY2(i3, IC + j1) = R_XY.Rows(i3).Columns (VX2(j1)) Next j1 XY2(i3, K2 + 1) = R_XY.Rows(i3).Columns(NY2) If XY2(i3, K2 + 1) <> 0 Then NTPES2 = NTPES2 + PES(i3) For j1 = 1 To K2 + 1 For k1 = j1 To K2 + 1 m(j1, k1) = m(j1, k1) + (XY2(i3, j1) * XY2(i3, k1) * PES(i3)) Next k1 Next j1 Next i3 For j1 = 1 To K2 + 1 For k1 = j1 + 1 To K2 + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 ReDim XPX(1 To K2 + 1, 1 To K2 + 1) As Double For i1 = 1 To K2 + 1 For j1 = 1 To K2 + 1 XPX(i1, j1) = m(i1, j1) Next j1 Next i1 Call C_G2SWEEP(0, IC, m, N, K2 + 1, 0.00000001, ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide MsgBox "El modelo de la 2a. etapa no es de ra ngo completo.", vbCritical, TITOL Exit Sub End If If IC = 1 Then LVAR2(1) = "Const." For i1 = 1 To NX2 LVAR2(IC + i1) = LVAR(VX2(i1), 1) Next i1 LVAR2(K2 + 1) = "Hazard" LVAR2(K2 + 2) = " Sigma" LVAR2(K2 + 3) = " Rho" LVAR2(K2 + 4) = LVAR(NY2, 1) End If Call ANALISIS(1) End Sub Private Sub Cancelar_Click()

Page 134: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

133

SORTIR = True NPES = 0 Unload Me End Sub Private Sub ANALISIS(opcio As Integer) 'TOBIT y HE CKMAN '''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul '''''''''''''''''''''''''''''''' ReDim OPT(1 To 4) OPT(1) = True OPT(2) = True OPT(3) = True CONVERG = Val(convergencia.Value) ITER = iteraciones.Value If LINK = 1 Then OPT(4) = contrastes.Value Else OPT (4) = False SIG = n_sig.Value Me.Hide End Sub Private Sub EXOGENES(opcio As Integer) Dim i1 As Integer AVISEXOGENES = False For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then AVISEXOGENES = True Exit For End If Next i1 If AVISEXOGENES Then For Each CTL In Me.Controls CTL.Enabled = True Next CTL If heckman Then contrastes.Enabled = False contrastes.Value = False End If Else NPES = 0 For Each CTL In Me.Controls If CTL.Name <> "Frame1" And CTL.Name <> "tob it" And CTL.Name <> "heckman" And _ CTL.Name <> "Label1" And CTL.Name <> "Lab el2" And CTL.Name <> "Label3" And CTL.Name <> "Labe l4" And _ CTL.Name <> "ys" And CTL.Name <> "xs" And CTL.Name <> "Cancelar" Then CTL.Enabled = False Next CTL For i1 = 1 To R_XY.Columns.Count ps.Selected(i1 - 1) = False ys2.Selected(i1 - 1) = False xs2.Selected(i1 - 1) = False Next i1 End If End Sub Private Sub tobit_Click() Dim i1 As Integer If tobit Then LINK = 1 Label1.Visible = False Label2.Visible = False Label3.Left = 100 Label4.Left = 195 Label5.Left = 290 Label6.Visible = False Label7.Visible = False ys.Left = 100 xs.Left = 195 ps.Left = 290 ys2.Visible = False xs2.Visible = False For i1 = 1 To R_XY.Columns.Count ys2.Selected(i1 - 1) = False xs2.Selected(i1 - 1) = False Next i1 End If

Page 135: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

134

End Sub Private Sub heckman_Click() If heckman Then LINK = 2 Label1.Visible = True Label2.Visible = True Label3.Left = 5 Label4.Left = 100 Label5.Left = 195 Label6.Visible = True Label7.Visible = True ys.Left = 5 xs.Left = 100 ps.Left = 195 ys2.Visible = True xs2.Visible = True contrastes.Enabled = False contrastes.Value = False End If End Sub Private Sub ps_Click() Dim i1 As Integer For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 End Sub Private Sub UserForm_Layout() n_sig.Move Height:=12, Left:=200, Top:=65, Width:=4 0 End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() Label4.Enabled = True xs.Enabled = True End Sub Private Sub ys2_Click() Label7.Enabled = True xs2.Enabled = True End Sub Private Sub xs_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call EXOGENES(1) End Sub

Page 136: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

135

Attribute VB_Name = "M4" Option Explicit Public K2 As Integer, LVAR2() As String, n0 As Long , NTPES2 As Double, NX2 As Integer, NY2 As Integer, _ VX2() As Integer, XY2() As Double, XY22() As Double Sub M4_(opcio As Integer) ''''''''''''''''' 'TOBIT y HECKMAN' ''''''''''''''''' ''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' ''''''''''''''''''''''''''''''''''' 'OPT(1) informació general ' 'OPT(2) estimació ' 'OPT(3) matriu variances ' 'OPT(4) contrasts (M4_04)' ''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria4: Mod elos Tobit y Heckman ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String, vconv(12 ) As String, viter(49) As Integer, vsig(5) As Doubl e For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 For i1 = 0 To 12 vconv(i1) = "1E-" & IIf(i1 < 7, 0, "") & i1 + 3 Next i1 For i1 = 50 To 1 Step -1 viter(50 - i1) = i1 Next i1 For i1 = 5 To 0 Step -1 If i1 > 0 Then vsig(5 - i1) = 0.05 * i1 Else vs ig(5 - i1) = 0.01 Next i1 TITOL = "MicroEconometría: Modelos Tobit y Heckman" h = Application.min(110, 11 * R_XY.Columns.Count) With M4_TobitHeckman .tobit.Value = True .Label3.Left = 100 .ys.Move Height:=h, Left:=100, Top:=65, Width:=90 .ys.List = v .Label4.Left = 195 .xs.Move Height:=h, Left:=195, Top:=65, Width:=90 .xs.List = v .Label5.Left = 290 .ps.Move Height:=h, Left:=290, Top:=65, Width:=90 .ps.List = v .ys2.Move Height:=h, Top:=65, Width:=90 .ys2.List = v .xs2.Move Height:=h, Top:=65, Width:=90 .xs2.List = v .convergencia.List = vconv .convergencia.Selected(5) = True .iteraciones.List = viter .iteraciones.Selected(25) = True .n_sig.List = vsig .n_sig.Selected(4) = True End With ERR_LEC = True SORTIR = False Do While ERR_LEC = True M4_TobitHeckman.Show If SORTIR Then ERR_LEC = False Loop Unload M4_TobitHeckman If SORTIR Then Exit Sub Dim avis As Boolean, it As Integer, lh As Double, n cond(1 To 2) As Double ReDim fivs(1 To K2 + 1) Call C_ORDENA(4, k + 1, k + 1) Call M4_00(1) If LINK = 1 Then Call M4_SCORING_TOBIT(avis, it, lh)

Page 137: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

136

If OPT(1) Then Call M4_01(avis, it, lh, 0) If OPT(2) Then Call M4_02(avis, k + 1, fivs) If OPT(3) Then Call M4_ESCRIPTURA_1(avis) If OPT(4) Then Call M4_04(1) Else Call M4_SCORING_HECKMAN(avis, it, lh) Call M4_MULTICOL(fivs, ncond) If OPT(1) Then Call M4_01(avis, 0, 0, ncond) If OPT(2) Then Call M4_02(avis, K2 + 3, fivs) If OPT(3) Then Call M4_ESCRIPTURA_1(avis) End If INOU = INOU + 1 End Sub Private Sub M4_00(opcio As Integer) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''' 'Valors inicials dels paràmetres i inici dels càlcu ls' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''' Dim i1 As Long, j1 As Integer, k1 As Integer If LINK = 1 Then ReDim m(1 To k + 1, 1 To k + 1) As Double For i1 = n0 + 1 To N For j1 = 1 To k + 1 For k1 = j1 To k + 1 m(j1, k1) = m(j1, k1) + (XY(IND(i1, 1), j1) * XY(IND(i1, 1), k1) * PES(IND(i1, 1))) Next k1 Next j1 Next i1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 m(k1, j1) = m(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, IC, m, N - n0, k + 1, 0.000000 01, False) ReDim B(1 To k + 1) B(k + 1) = 1 / Sqr(m(k + 1, k + 1) / (N - n0)) For j1 = 1 To k B(j1) = m(j1, k + 1) * B(k + 1) Next j1 Else ReDim B(1 To k + 1) For j1 = 1 To k + 1 B(j1) = G2SWEEP(j1, k + 1) Next j1 End If End Sub Private Sub M4_SCORING_TOBIT(avis, it, lh) ''''''''''''''''''''''''''''''''''''''''''''''''' 'Algoritme de càlcul, métode "SCORING" del TOBIT' ''''''''''''''''''''''''''''''''''''''''''''''''' Dim i1 As Long, i2 As Integer, j1 As Integer, k1 As Integer, l1 As Integer Dim a1 As Double, a2 As Double, c As Double, cdf As Double, lh1 As Double, _ pi_ As Double, pi_2 As Double, pdf As Double, Y As Double, z As Double ReDim aux(1 To k + 1, 1 To k + 1) As Double, d_g(1 To 2 * (k + 1)) As Double, _ MCOV(1 To k + 1, 1 To k + 1) c = 1 lh1 = 0 pi_ = Sqr(2 * Application.pi) pi_2 = (0.5 * Log(pi_ ^ 2)) For it = 1 To ITER ReDim m(1 To k + 2, 1 To k + 2) As Double lh = 0 For i1 = 1 To n0 Y = XY(IND(i1, 1), k + 1) z = 0 For j1 = 1 To k z = z + (XY(IND(i1, 1), j1) * B(j1)) Next j1 pdf = Exp(-z * z / 2) / pi_ cdf = Application.NormSDist(z) lh = lh + (Log(1 - cdf) * PES(IND(i1, 1))) a1 = pdf / (1 - cdf) a2 = a1 * (z - a1) For j1 = 1 To k For k1 = j1 To k m(j1, k1) = m(j1, k1) - (XY(IND(i1, 1), j1) * a2 * XY(IND(i1, 1), k1) * PES(IND(i1, 1) ))

Page 138: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

137

Next k1 m(j1, k + 2) = m(j1, k + 2) - (a1 * XY( IND(i1, 1), j1) * PES(IND(i1, 1))) Next j1 Next i1 For i1 = n0 + 1 To N Y = XY(IND(i1, 1), k + 1) z = 0 For j1 = 1 To k z = z + (XY(IND(i1, 1), j1) * B(j1)) Next j1 a1 = (B(k + 1) * Y) - z lh = lh + ((Log(B(k + 1)) - (0.5 * (a1 ^ 2) ) - pi_2)) * PES(IND(i1, 1)) For j1 = 1 To k For k1 = j1 To k m(j1, k1) = m(j1, k1) + (XY(IND(i1, 1), j1) * XY(IND(i1, 1), k1) * PES(IND(i1, 1))) Next k1 m(j1, k + 1) = m(j1, k + 1) - (Y * XY(I ND(i1, 1), j1) * PES(IND(i1, 1))) m(j1, k + 2) = m(j1, k + 2) + (a1 * XY( IND(i1, 1), j1) * PES(IND(i1, 1))) Next j1 m(k + 1, k + 1) = m(k + 1, k + 1) + (((B(k + 1) ^ (-2)) + (Y ^ 2)) * PES(IND(i1, 1))) m(k + 1, k + 2) = m(k + 1, k + 2) + (((1 / B(k + 1)) - (a1 * Y)) * PES(IND(i1, 1))) Next i1 For j1 = 1 To k + 2 For k1 = j1 + 1 To k + 2 m(k1, j1) = m(j1, k1) Next k1 If j1 < k + 2 Then d_g(j1) = m(j1, k + 2) Next j1 Call C_G2SWEEP(1, IC, m, N, k + 2, 0.00000001, False) For j1 = 1 To k + 1 B(j1) = B(j1) + m(j1, k + 2) d_g(k + 1 + j1) = m(j1, k + 2) Next j1 c = Application.max(Abs(lh1 - lh), Application. SumSq(d_g)) lh1 = lh If c <= CONVERG Then avis = True Exit For End If Next it it = it - 1 ''''''''''''''''' 'Re-parametritza' ''''''''''''''''' B(k + 1) = 1 / B(k + 1) For j1 = 1 To k B(j1) = B(j1) * B(k + 1) For k1 = 1 To k If k1 = j1 Then aux(j1, k1) = B(k + 1) Else aux(j1, k1) = 0 Next k1 aux(j1, k + 1) = -B(j1) * B(k + 1) aux(k + 1, j1) = 0 Next j1 aux(k + 1, k + 1) = -B(k + 1) ^ 2 For i2 = 1 To k + 1 For j1 = 1 To k + 1 For k1 = 1 To k + 1 For l1 = 1 To k + 1 MCOV(i2, j1) = MCOV(i2, j1) + (aux( j1, k1) * m(l1, k1) * aux(i2, l1)) Next l1 Next k1 Next j1 Next i2 End Sub Private Sub M4_SCORING_HECKMAN(avis, it, lh) '''''''''''''''''''''''''''''''''''''''''''''''' 'Algoritme de càlcul, métode "HECKMAN 2 etapes"' '''''''''''''''''''''''''''''''''''''''''''''''' Dim i1 As Long, i2 As Integer, j1 As Integer, k1 As Integer, l1 As Integer Dim aux As Double, a1 As Double, a2 As Double, conv As Double, cdf As Double, _ lh1 As Double, pdf As Double, Y As Double, z As Double ReDim bprobit(1 To k) As Double, d_g(1 To 2 * k) As Double ''''''''''''''''''''''''''' '1a. etapa: model "PROBIT"' ''''''''''''''''''''''''''' conv = 1

Page 139: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

138

lh1 = 0 aux = 1 / Sqr(2 * Application.pi) For j1 = 1 To k bprobit(j1) = B(j1) Next j1 For it = 1 To ITER ReDim mprobit(1 To k + 1, 1 To k + 1) As Double lh = 0 For i1 = 1 To N z = 0 For j1 = 1 To k z = z + (XY(i1, j1) * bprobit(j1)) Next j1 pdf = Exp(-z * z / 2) * aux cdf = Application.NormSDist(z) a1 = pdf / cdf a2 = pdf / (1 - cdf) For j1 = 1 To k For k1 = j1 To k mprobit(j1, k1) = mprobit(j1, k1) + (XY(i1, j1) * a1 * a2 * XY(i1, k1) * PES(i1)) Next k1 If XY(i1, k + 1) = 0 Then mprobit(j1, k + 1) = mprobit(j1, k + 1) + (-a2 * XY(i1, j1) * PES(i1)) Else mprobit(j1, k + 1) = mprobit(j1, k + 1) + (a1 * XY(i1, j1) * PES(i1)) End If Next j1 If XY(i1, k + 1) = 0 Then lh = lh + (Log(1 - cdf) * PES(i1)) Else lh = lh + (Log(cdf) * PES(i1 )) Next i1 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 mprobit(k1, j1) = mprobit(j1, k1) Next k1 If j1 < k + 1 Then d_g(j1) = mprobit(j1, k + 1) Next j1 Call C_G2SWEEP(1, IC, mprobit, N, k + 1, 0.00000 001, False) For j1 = 1 To k bprobit(j1) = bprobit(j1) + mprobit(j1, k + 1) d_g(k + j1) = mprobit(j1, k + 1) Next j1 conv = Application.max(Abs(lh1 - lh), Applicatio n.SumSq(d_g)) lh1 = lh If conv <= CONVERG Then avis = True Exit For End If Next it it = it - 1 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' '2a. etapa MQ sobre valors positius de y, ampliant X amb pdf/cdf' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''' Dim delta As Double ReDim MCOV(1 To K2 + 2, 1 To K2 + 2), xy_(1 To K2 + 2) As Double, XY22(1 To N - n0, 1 To K2 + 1) delta = 0 For i1 = n0 + 1 To N For j1 = 1 To K2 xy_(j1) = XY2(IND(i1, 1), j1) XY22(i1 - n0, j1) = xy_(j1) Next j1 z = 0 For j1 = 1 To k z = z + (XY(IND(i1, 1), j1) * bprobit(j1)) Next j1 pdf = Exp(-z * z / 2) * aux cdf = Application.NormSDist(z) xy_(K2 + 1) = pdf / cdf XY22(i1 - n0, K2 + 1) = xy_(K2 + 1) xy_(K2 + 2) = XY2(IND(i1, 1), K2 + 1) For j1 = 1 To K2 + 2 For k1 = j1 To K2 + 2 MCOV(j1, k1) = MCOV(j1, k1) + (xy_(j1) * xy_(k1) * PES(IND(i1, 1))) Next k1 Next j1 delta = delta + (((pdf / cdf) * ((pdf / cdf) - z)) * PES(IND(i1, 1))) Next i1 For j1 = 1 To K2 + 2 For k1 = j1 + 1 To K2 + 2 MCOV(k1, j1) = MCOV(j1, k1) Next k1

Page 140: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

139

Next j1 ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' 'este paso es para utilizarlo luego en el cálculo d el número de condición y de FIV ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''' ReDim XPX(1 To K2 + 1, 1 To K2 + 1) For i1 = 1 To K2 + 1 For j1 = 1 To K2 + 1 XPX(i1, j1) = MCOV(i1, j1) Next j1 Next i1 Call C_G2SWEEP(1, IC, MCOV, N - n0, K2 + 2, 0.00000 001, False) ReDim B(1 To K2 + 3) For j1 = 1 To K2 + 1 B(j1) = MCOV(j1, K2 + 2) Next j1 '''''''''''''''''''''''' 'Parametres sigma i rho' '''''''''''''''''''''''' Dim sigma2 As Double, rho2 As Double delta = delta / (N - n0) sigma2 = (MCOV(K2 + 2, K2 + 2) / (N - n0)) + (delta * (B(K2 + 1) ^ 2)) B(K2 + 2) = Sqr(sigma2) rho2 = (B(K2 + 1) ^ 2) / sigma2 B(K2 + 3) = (B(K2 + 1) / Abs(B(K2 + 1))) * Sqr(rho2 ) ''''''''''''''''''''''''''''''''''''' 'Matriu de variàncies i covariàncies' ''''''''''''''''''''''''''''''''''''' Dim maux() As Double ReDim IXPX(1 To K2 + 1, 1 To K2 + 1), maux(1 To K2 + 1, 1 To k), _ q(1 To K2 + 1, 1 To K2 + 1) As Double 'quan l a 2a. etapa K2<K q(1 To K2 + 1, 1 To K) For j1 = 1 To K2 + 1 For k1 = 1 To K2 + 1 IXPX(j1, k1) = MCOV(j1, k1) Next k1 Next j1 ReDim MCOV(1 To K2 + 1, 1 To K2 + 1) For i1 = n0 + 1 To N For j1 = 1 To K2 xy_(j1) = XY2(IND(i1, 1), j1) Next j1 z = 0 For j1 = 1 To k z = z + (XY(IND(i1, 1), j1) * bprobit(j1)) Next j1 pdf = Exp(-z * z / 2) * aux cdf = Application.NormSDist(z) delta = (pdf / cdf) * ((pdf / cdf) - z) xy_(K2 + 1) = pdf / cdf xy_(K2 + 2) = XY2(IND(i1, 1), K2 + 1) For j1 = 1 To K2 + 1 For k1 = j1 To K2 + 1 MCOV(j1, k1) = MCOV(j1, k1) + (xy_(j1) * (1 - (rho2 * delta)) * xy_(k1) * PES(IND(i1, 1))) Next k1 For k1 = 1 To k maux(j1, k1) = maux(j1, k1) + (xy_(j1) * delta * XY(IND(i1, 1), k1) * PES(IND(i1, 1))) Next k1 Next j1 Next i1 For j1 = 1 To K2 + 1 For k1 = j1 + 1 To K2 + 1 MCOV(k1, j1) = MCOV(j1, k1) Next k1 Next j1 'q = Application.MMult(Application.MMult(maux, mpro bit), Application.Transpose(maux)) For i2 = 1 To K2 + 1 For j1 = 1 To K2 + 1 For k1 = 1 To k For l1 = 1 To k q(i2, j1) = q(i2, j1) + (maux(i2, k 1) * mprobit(k1, l1) * maux(j1, l1)) Next l1 Next k1 Next j1 Next i2 For j1 = 1 To K2 + 1

Page 141: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

140

For k1 = 1 To K2 + 1 MCOV(j1, k1) = MCOV(j1, k1) + (rho2 * q(j1, k1)) Next k1 Next j1 ReDim maux(1 To K2 + 1, 1 To K2 + 1) For i2 = 1 To K2 + 1 For j1 = 1 To K2 + 1 For k1 = 1 To K2 + 1 For l1 = 1 To K2 + 1 maux(i2, j1) = maux(i2, j1) + (IXPX (k1, j1) * MCOV(k1, l1) * IXPX(l1, i2)) Next l1 Next k1 Next j1 Next i2 For j1 = 1 To K2 + 1 For k1 = 1 To K2 + 1 MCOV(j1, k1) = sigma2 * maux(j1, k1) Next k1 Next j1 End Sub Private Sub M4_MULTICOL(fivs, ncond) ''''''''''''''''''''''''''''''''''' 'Indicadors de multicol·linealitat' ''''''''''''''''''''''''''''''''''' Dim i1 As Integer, j1 As Integer, k1 As Integer, de n As Double, noint As Boolean, num1 As Double, num2 As Double ReDim corr_v(1 To K2 - IC + 1, 1 To K2 - IC + 1) As Double, _ fiv(1 To K2 - IC + 2, 1 To K2 - IC + 2) As Do uble, SUMS(1 To K2 + 1, 1 To 3), _ valp(1 To K2 + 1) As Double, varp(1 To K2 + 1 , 1 To K2 + 1) As Double For j1 = 1 To K2 + 1 SUMS(j1, 1) = XPX(1, j1) / NTPES2 SUMS(j1, 2) = XPX(j1, j1) SUMS(j1, 3) = XPX(j1, j1) - IIf(IC = 1, ((SUMS( j1, 1) ^ 2) * NTPES2), 0) Next j1 For i1 = 1 To K2 + 1 - IC For j1 = i1 + 1 To K2 + 1 - IC num1 = XPX(i1 + IC, j1 + IC) If IC = 1 Then num2 = (SUMS(i1 + IC, 1) * S UMS(j1 + IC, 1) * NTPES2) - (SUMS(i1 + IC, 1) * XPX (1, j1 + IC)) - (SUMS(j1 + IC, 1) * XPX(1, i1 + IC)) Else nu m2 = 0 den = SUMS(i1 + IC, IIf(IC = 1, 3, 2)) * SU MS(j1 + IC, IIf(IC = 1, 3, 2)) corr_v(i1, j1) = (num1 + num2) / Sqr(den) If i1 <> j1 Then corr_v(j1, i1) = corr_v(i1 , j1) Next j1 corr_v(i1, i1) = 1 Next i1 For i1 = 1 To K2 + 1 - IC For j1 = 1 To K2 + 1 - IC fiv(i1, j1) = corr_v(i1, j1) Next j1 Next i1 Call C_G2SWEEP(1, 0, fiv, N, K2 - IC + 2, 0.0000000 1, False) For i1 = IC + 1 To K2 + 1 fivs(i1) = fiv(i1 - IC, i1 - IC) Next i1 For j1 = 1 To IIf(IC = 1, 2, 1) If j1 = 1 Then noint = False Else noint = True k1 = IIf(j1 = 1, K2 + 1, K2) Call M1_06_1(valp, varp, corr_v, 1, N - n0, k1, noint) ncond(j1) = Sqr(valp(1) / valp(UBound(valp))) Next j1 End Sub Private Sub M4_01(avis, it, lh, ncond) '''''''''''''''''''''''''''''''''''''''''''' 'Escriptura de la informació de l'estimació' '''''''''''''''''''''''''''''''''''''''''''' If LINK = 1 Then Dim c As Integer, i3 As Long, N0p As Double For i3 = 1 To n0 N0p = N0p + R_XY.Rows(IND(i3, 1)).Columns(NP ES)

Page 142: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

141

Next i3 If avis Then c = 0 Else c = 1 ReDim R(1 To 9 + IIf(NPES <> 0, 3, 0), 1 To 3 + c) R(1, 1) = "Modelo" R(1, 3 + c) = "TOBIT" R(2, 1) = "Técnica de optimización" R(2, 3 + c) = "''Scoring'" R(3, 1) = "Variable dependiente" R(3, 3 + c) = LVAR(k + 1, 2) If NPES <> 0 Then R(4, 1) = "Número obs. (" & LVAR(k + 1, 2) & " = 0)" R(4, 3 + c) = n0 R(5, 1) = "Número obs. (" & LVAR(k + 1, 2) & " = 0) pond." R(5, 3 + c) = N0p / NTPESM R(6, 1) = "Número obs. (" & LVAR(k + 1, 2) & " > 0)" R(6, 3 + c) = N - n0 R(7, 1) = "Número obs. (" & LVAR(k + 1, 2) & " > 0) pond." R(7, 3 + c) = N - (N0p / NTPESM) R(12, 1) = "Variable de ponderación" R(12, 3 + c) = LVAR(NPES, 1) Else R(4, 1) = "Número obs. (" & LVAR(k + 1, 2) & " = 0)" R(4, 3 + c) = n0 R(5, 1) = "Número obs. (" & LVAR(k + 1, 2) & " > 0)" R(5, 3 + c) = N - n0 End If R(6 + IIf(NPES <> 0, 2, 0), 1) = "Total observac iones" R(6 + IIf(NPES <> 0, 2, 0), 3 + c) = N R(7 + IIf(NPES <> 0, 2, 0), 1) = "Iteraciones ef ectuadas" R(7 + IIf(NPES <> 0, 2, 0), 3 + c) = it R(8 + IIf(NPES <> 0, 2, 0), 1) = "Criterio de co nvergencia" R(8 + IIf(NPES <> 0, 2, 0), 3 + c) = CONVERG & I If(avis, "", " No alcanzado!!!") R(9 + IIf(NPES <> 0, 2, 0), 1) = "Log. L" R(9 + IIf(NPES <> 0, 2, 0), 3 + c) = lh LVAR(k + 1, 2) = " Escala" Else Dim i1 As Integer, aux As String aux = "" For i1 = 1 To k aux = aux & LVAR(i1, 2) & IIf(i1 <> k, ",", ".") Next i1 ReDim R(1 To IIf(IC = 1, 10, 9) + IIf(NPES = 0, 0, 1), 1 To 9) R(1, 1) = "Modelo" R(1, 3) = "HECKMAN" R(2, 1) = "Técnica de optimización" R(2, 3) = "Heckman 2 etapas" & IIf(avis, "", " ( Convergencia no alcanzada en la 1a. etapa!!!)") R(3, 1) = "Var. dependiente (Etapa 1)" R(3, 3) = LVAR(k + 1, 2) R(4, 1) = "Observaciones (" & LVAR(k + 1, 2) & " = 0)" R(4, 3) = n0 R(5, 1) = "Observaciones (" & LVAR(k + 1, 2) & " " & Chr(172) & "0)" R(5, 3) = N - n0 R(6, 1) = "Var. independ. (Etapa 1)" R(6, 3) = aux R(7, 1) = "Observaciones (Etapa 1)" R(7, 3) = N R(7, 1) = "Var. dependiente (Etapa 2)" R(7, 3) = LVAR2(K2 + 4) R(8, 1) = "Observaciones (Etapa 2)" R(8, 3) = N - n0 R(9, 1) = "Número condición (no centrado)" R(9, 3) = ncond(1) If IC = 1 Then R(10, 1) = "Número condición (centrado)" R(10, 3) = ncond(2) End If If NPES <> 0 Then R(10 + IC, 1) = "Variable de ponderación" R(10 + IC, 3) = LVAR(NPES, 1) End If End If avis = True If OPT(4) Then avis = False If UBound(MCOV, 1) <= 18 Then avis = False Call M4_ESCRIPTURA(1, "Información general de la es timación", avis) End Sub Private Sub M4_02(avis, dim2 As Integer, fivs)

Page 143: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

142

''''''''''''''''''''''''''' 'Escriptura de l'estimació' ''''''''''''''''''''''''''' Dim i1 As Integer, j1 As Integer, normal ReDim R(1 To dim2 + 2, 1 To IIf(LINK = 1, 9, 8)) '9,7 R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "Error" & Chr(10) & "Estándar" R(1, 4) = IIf(LINK = 1, "Valor c" & Chr(178), "Val or t") R(1, 5) = IIf(LINK = 1, "Prob > c" & Chr(178), "Pro b |t|") R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" If LINK = 2 Then R(1, 8) = "F.I.V." normal = Application.NormSInv(SIG / 2) For i1 = 1 To dim2 - IIf(LINK = 1, 0, 2) R(i1 + 2, 2) = B(i1) R(i1 + 2, 3) = Sqr(MCOV(i1, i1)) If i1 < IIf(LINK = 1, dim2, dim2 - 2) Then R(i1 + 2, 4) = (R(i1 + 2, 2) / R(i1 + 2, 3)) ^ IIf(LINK = 1, 2, 1) R(i1 + 2, 5) = IIf(LINK = 1, Application.Chi Dist(R(i1 + 2, 4), 1), Application.TDist(Abs(R(i1 + 2, 4)), N - dim2, 2)) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0,0001", R(i1 + 2, 5)) R(i1 + 2, 6) = B(i1) + (normal * R(i1 + 2, 3 )) R(i1 + 2, 7) = B(i1) - (normal * R(i1 + 2, 3 )) End If If LINK = 2 And i1 < dim2 - 1 Then R(i1 + 2, 8) = fivs(i1) Next i1 If LINK = 1 Then For i1 = 1 To dim2 R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & ")" Next i1 R(1, 8) = "Ef. marginales en la media" R(2, 8) = "E(y)" R(2, 9) = "E(y | y > 0)" Dim cdf, pdf, z ReDim aux(1 To k) If IC = 1 Then aux(1) = 1 For i1 = 1 To NX aux(i1 + IC) = Application.Average(R_XY.Colu mns(VX(i1))) Next i1 z = 0 For i1 = 1 To k z = z + (aux(i1) * B(i1)) Next i1 z = z / B(k + 1) cdf = Application.NormSDist(z) pdf = Exp(-z * z / 2) / Sqr(2 * Application.pi) For i1 = 1 To k R(i1 + 2, 8) = B(i1) * cdf R(i1 + 2, 9) = B(i1) * (1 - (z * pdf / cdf) - ((pdf / cdf) ^ 2)) Next i1 Else For i1 = 1 To dim2 - 3 R(i1 + 2, 1) = "b" & i1 & "(" & LVAR2(i1) & ")" Next i1 R(dim2, 1) = "b" & i1 & "(" & LVAR2(K2 + 1) & ") " R(dim2 + 1, 1) = LVAR2(K2 + 2) R(dim2 + 2, 1) = LVAR2(K2 + 3) For i1 = dim2 - 2 To dim2 R(i1 + 2, 2) = B(i1) Next i1 End If If dim2 > 27 Then avis = True Else avis = False Call M4_ESCRIPTURA(3, "Resultados de la estimación" , avis) End Sub Private Sub M4_04(opcio As Integer) ''''''''''''''''''''''''''''''''''''''' 'Tests basats en residus generalitzats' ''''''''''''''''''''''''''''''''''''''' Dim i1 As Long, i2 As Integer, j1 As Integer, k1 As Integer Dim aux, cdf, dim1 As Integer, d1 As Integer, d2 As Integer, pdf, Y, z dim1 = Application.max(3, k + 1 - IC) ReDim E(1 To 4), maux(1 To dim1, 1 To dim1, 1 To 4) , xy_(1 To dim1) aux = 1 / Sqr(2 * Application.pi) For i1 = 1 To N

Page 144: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

143

z = 0 For j1 = 1 To k z = z + (XY(i1, j1) * (B(j1))) Next j1 Y = (XY(i1, k + 1) - z) / B(k + 1) z = z / B(k + 1) If XY(i1, k + 1) = 0 Then cdf = Application.NormSDist(z) pdf = Exp(-z * z / 2) * aux d1 = 1 d2 = 0 E(1) = pdf / (1 - cdf) Else cdf = 0 pdf = 0 d1 = 0 d2 = 1 E(1) = 0 End If E(2) = (d1 * z * E(1)) + (d2 * ((Y ^ 2) - 1)) E(3) = (-d1 * (2 + (z ^ 2)) * E(1)) + (d2 * (Y ^ 3)) E(4) = (d1 * ((3 * z) + (z ^ 3)) * E(1)) + (d2 * ((Y ^ 4) - 3)) For i2 = 1 To 4 If i2 < 3 Then dim1 = 2 xy_(1) = E(i2 + 2) ElseIf i2 = 3 Then dim1 = 3 xy_(1) = E(3) xy_(2) = E(4) Else dim1 = k + 1 - IC For j1 = IC + 1 To k xy_(j1 - IC) = E(2) * XY(i1, j1) Next j1 End If xy_(dim1) = 1 For j1 = 1 To dim1 For k1 = j1 To dim1 maux(j1, k1, i2) = maux(j1, k1, i2) + (xy_(j1) * xy_(k1)) Next k1 Next j1 Next i2 Next i1 dim1 = Application.max(3, k + 1 - IC) ReDim m(1 To dim1, 1 To dim1), R(1 To 5, 1 To 5), t ests(1 To 4) R(1, 1) = "Hipótesis nula" R(1, 3) = "Valor c" & Chr(178) R(1, 4) = "gl" R(1, 5) = "Prob > c" & Chr(178) R(2, 1) = "Asimetría" R(3, 1) = "Apuntamiento" R(4, 1) = "Normalidad" R(5, 1) = "Homoscedasticidad" For i2 = 1 To 4 If i2 < 3 Then dim1 = 2 ElseIf i2 = 3 Then dim1 = 3 Else dim1 = k + 1 - IC End If For j1 = 1 To dim1 For k1 = j1 + 1 To dim1 maux(k1, j1, i2) = maux(j1, k1, i2) Next k1 Next j1 For j1 = 1 To dim1 For k1 = 1 To dim1 m(j1, k1) = maux(j1, k1, i2) Next k1 Next j1 Call C_G2SWEEP(1, IC, m, N, dim1, 0.000000001, False) tests(i2) = N - m(dim1, dim1) R(i2 + 1, 3) = tests(i2) R(i2 + 1, 4) = IIf(i2 <> 4, dim1 - 1, dim1 - 1) R(i2 + 1, 5) = Application.ChiDist(R(i2 + 1, 3) , R(i2 + 1, 4)) R(i2 + 1, 5) = IIf(R(i2 + 1, 5) < 0.0001, "< 0, 0001", R(i2 + 1, 5)) Next i2 Call M4_ESCRIPTURA(2, "Contrastes basados en residu os generalizados", True) End Sub Private Sub M4_ESCRIPTURA_1(avis)

Page 145: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

144

'''''''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A L'ESCRIPTURA DE MATRIUS' '''''''''''''''''''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, j1 As Integer, j2 As Integer Dim dim1 As Integer, dim2 As Integer, maxim2 As Int eger, resta2 As Integer dim1 = UBound(MCOV, 1) dim2 = IIf(dim1 <= 9, dim1, 9) maxim2 = IIf(dim1 <= 9, 1, Int(dim1 / 9)) resta2 = IIf(dim1 <= 9, 0, dim1 - (maxim2 * 9)) If resta2 <> 0 Then maxim2 = maxim2 + 1 avis = False For j1 = 1 To maxim2 ReDim R(1 To dim1 + 1, 1 To IIf(j1 < maxim2, di m2, IIf(j1 = 1, dim2, IIf(resta2 <> 0, resta2, dim2 ))) + 1) For j2 = 1 To IIf(j1 < maxim2, dim2, IIf(j1 = 1 , dim2, IIf(resta2 <> 0, resta2, dim2))) i2 = j2 + ((j1 - 1) * 9) If LINK = 1 Then R(1, j2 + 1) = "b" & i2 & "(" & LVAR(i2, 2) & ")" Else R(1, j2 + 1) = "b" & i2 & "(" & LVAR2(i2 ) & ")" End If Next j2 For i1 = 1 To dim1 If LINK = 1 Then R(i1 + 1, 1) = "b" & i1 & "(" & LVAR(i1, 2) & ")" Else R(i1 + 1, 1) = "b" & i1 & "(" & LVAR2(i1 ) & ")" End If For j2 = 1 To IIf(j1 < maxim2, dim2, IIf(j1 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) R(i1 + 1, j2 + 1) = MCOV(i1, j2 + ((j1 - 1) * 9)) Next j2 Next i1 If dim1 <= 9 Then avis = True ElseIf dim1 <= 18 Then avis = IIf(j1 = 2, True, False) ElseIf dim1 <= 27 Then avis = IIf(j1 = 1 Or j1 = 3, True, False) ElseIf dim1 <= 36 Then avis = IIf(j1 = 2, False, True) Else avis = True End If Call M4_ESCRIPTURA(4, "Matriz de varianzas y co varianzas" & IIf(j1 = 1, "", "(cont.)"), avis) Next j1 End Sub Private Sub M4_ESCRIPTURA(opcio As Integer, titol1 As String, avis) '''''''''''''''''''' 'Escriptura general' '''''''''''''''''''' Sheets(FULL_R).Activate Dim i1 As Integer, j1 As Integer ''''''''''''''''''''''''''''''''''''''''''''''''''' 'opcio=1 ==> Informació general de l'estimació ' 'opcio=2 ==> Tests basats en residus generalitzats' 'opcio=3 ==> Estimació ' 'opcio=4 ==> Matriu de variàncies i covariàncies ' ''''''''''''''''''''''''''''''''''''''''''''''''''' Dim c(1 To 2) As Integer c(1) = UBound(R, 1) c(2) = UBound(R, 2) With Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 10) ) .ColumnWidth = 9.5 With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter .Interior.ColorIndex = 2 .RowHeight = 11 .VerticalAlignment = xlCenter End With With Cells(F - 1, 1) .Font.Bold = True

Page 146: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

145

.HorizontalAlignment = xlLeft .Value = titol1 End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) .Borders(xlEdgeTop).LineStyle = xlDouble .Borders(xlEdgeBottom).LineStyle = xlDouble .Interior.ColorIndex = 37 .Value = R End With With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Font.Bold = True .HorizontalAlignment = xlLeft End With If opcio <> 1 Then If opcio = 3 Then i1 = 1 Else i1 = 0 With Range(Cells(F, 1), Cells(F + i1, c(2))) .Borders(xlEdgeBottom).LineStyle = xlContinuou s .Font.Bold = True End With End If If opcio = 1 Then 'Quadre informació For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , 2)).MergeCells = True With Cells(F + i1 - 1, 3) .HorizontalAlignment = xlLeft If i1 >= 4 And i1 <= IIf(LINK = 1, IIf(NPE S <> 0, 9, 7), 8) Then .NumberFormat = "###,0" If LINK = 2 And i1 = 9 Then .NumberFormat = "###,0.00" If LINK = 1 Then If i1 = IIf(NPES <> 0, 10, 8) Then .Num berFormat = "0.00E+00" If i1 = IIf(NPES <> 0, 11, 9) Then If Abs(R(i1, 3)) >= 1000 And Abs(R(i 1, 3)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, 3)) < 1000 And Abs(R(i1 , 3)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000 " End If End If End With Next i1 ElseIf opcio = 2 Then 'Tests residus generalitzats For i1 = 1 To c(1) With Range(Cells(F + i1 - 1, 1), Cells(F + i 1 - 1, 2)) .MergeCells = True End With Next i1 Cells(F, c(2) - 2).Characters(8, 1).Font.Name = "symbol" Cells(F, c(2) - 2).Characters(8, 1).Font.Bold = True Cells(F, c(2)).Characters(8, 1).Font.Name = "sym bol" Cells(F, c(2)).Characters(8, 1).Font.Bold = True For j1 = c(2) - 2 To c(2) With Range(Cells(F, j1), Cells(F + c(1), j1) ) If j1 = c(2) - 2 Then .NumberFormat = "### ,0.000" If j1 = c(2) - 1 Then .NumberFormat = "0" If j1 = c(2) Then .NumberFormat = "0.0000" End With Next j1 ElseIf opcio = 3 Then 'Quadre estimació For j1 = 1 To 6 Range(Cells(F, j1), Cells(F + 1, j1)).MergeC ells = True Next j1 For j1 = 6 To IIf(LINK = 1, 8, 6) Step IIf(LINK = 1, 2, 1) With Range(Cells(F, j1), Cells(F, j1 + 1)) If LINK = 1 Then .Borders(xlBottom).LineSt yle = xlContinuous .MergeCells = True End With Next j1 If LINK = 2 Then Range(Cells(F, 8), Cells(F + 1, 8)).MergeCells = True If LINK = 1 Then Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1).Font.Name = "symbol" Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1).Font.Bold = True End If Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Name = "symbol" Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Bold = True Range(Cells(F + 2, 4), Cells(F + c(1) - 1, 4)).N umberFormat = "###,0.000" Range(Cells(F + 2, 5), Cells(F + c(1) - 1, 5)).N umberFormat = "0.0000" Range(Cells(F + c(1) - IIf(LINK = 1, 1, 3), 1), Cells(F + c(1) - IIf(LINK = 1, 1, 3), c(2))).Borders(xlTop).LineStyle = xlDash For i1 = 3 To c(1) For j1 = 2 To c(2) If (j1 <> 4 And j1 <> 5) Then With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R (i1, j1)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, j1)) < 1000 And Abs(R( i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000 000"

Page 147: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

146

End With End If Next j1 Next i1 ElseIf opcio = 4 Then 'Matriu variàncies i covarià ncies Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Borde rs(xlRight).LineStyle = xlContinuous For i1 = 2 To c(1) Cells(F + i1 - 1, 1).Characters(1, 1).Font.N ame = "symbol" Cells(F + i1 - 1, 1).Characters(1, 1).Font.B old = True Cells(F, i1).Characters(1, 1).Font.Name = "s ymbol" Cells(F, i1).Characters(1, 1).Font.Bold = Tr ue Next i1 End If If avis Then ActiveWindow.SelectedSheets.HPageBreak s.Add (Cells(F + c(1), 1)) F = F + c(1) + 2 Sheets(FULL).Activate End Sub

Page 148: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

147

Attribute VB_Name = "M5_LogitM" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVIS_ATRIBUTOS_INDIVIDUALES As Boolean, AVIS_AT RIBUTOS_ELECCION As Boolean Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Long, j1 As Integer, k1 As Integer, l1 As Integer JJJ = elecciones.Value ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then NE = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la 'elección'.", vbCrit ical, TITOL Exit Sub End If NPES = 0 For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 If NPES <> 0 Then If NE = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(NE, 1) & " no puede ser la 'elecc ión' y factor de elevación.", vbCritical, TITOL Exit Sub End If End If If LINK = 1 Or LINK = 3 Then ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If xs1.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VAI(1 To i2) VAI(i2) = i1 KI = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Al escoger el modelo multinomial o mi xto, debe seleccionar algún atributo individual.", vbCritical, TITOL Exit Sub End If For i1 = 1 To KI If NE = VAI(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NE, 1) & " no puede ser la 'e lección' y atributo individual.", vbCritical, TITOL Exit Sub End If If NPES = VAI(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(VAI(i1), 1) & " no puede ser atributo individual y factor de elevación.", vbCrit ical, TITOL Exit Sub End If Next i1 End If If LINK = 2 Or LINK = 3 Then i2 = 0 ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If xs2.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VAE(1 To i2) VAE(i2) = i1

Page 149: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

148

KE = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Al escoger el modelo condicional o mi xto, debe seleccionar algún atributo para la 'elecc ión'.", vbCritical, TITOL Exit Sub End If For i1 = 1 To KE If NE = VAE(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NE, 1) & " no puede ser la 'e lección' y atributo de la 'elección'.", vbCritical, TITOL Exit Sub End If If NPES = VAE(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(VAE(i1), 1) & " no puede ser atributo de la 'elección' y factor de elevación.", vbCritical, TITOL Exit Sub End If Next i1 End If If LINK <> 1 Then If KE Mod JJJ <> 0 Then ERR_LEC = True Me.Hide MsgBox "El número de atributos de la 'elecció n' debe ser múltiplo de " & JJJ & ".", vbCritical, TITOL Exit Sub End If End If If Application.CountIf(R_XY.Columns(NE), ">" & Str( JJJ - 1)) <> 0 Or Application.CountIf(R_XY.Columns( NE), "<0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Los valores de " & LVAR(NE, 1) & " deben estar entre 0 y " & JJJ - 1 & ".", vbCritical, TIT OL Exit Sub End If For i1 = 0 To JJJ - 1 If Application.CountIf(R_XY.Columns(NE), "=" & Str(i1)) = 0 Then ERR_LEC = True Me.Hide MsgBox "El valor " & i1 & " no aparece ningu na vez en la variable " & LVAR(NE, 1) & ".", vbCrit ical, TITOL Exit Sub End If Next i1 If Application.Count(R_XY.Columns(NE)) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de " & LVAR(NE, 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If If NPES <> 0 Then If Application.Count(R_XY.Columns(NPES)) <> N Or Application.CountIf(R_XY.Columns(NPES), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N PES, 1) & " es negativo, nulo o no numérico.", vbCr itical, TITOL Exit Sub End If End If If LINK <> 1 Then For i1 = 1 To KE If Application.Count(R_XY.Columns(VAE(i1))) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de " & LVAR(VAE(i1), 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If Next i1 End If If LINK <> 2 Then For i1 = 1 To KI If Application.Count(R_XY.Columns(VAI(i1))) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de " & LVAR(VAI(i1), 1) & " no es numérico.", vbCritical, TITOL

Page 150: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

149

Exit Sub End If Next i1 End If If Constante.Value = True Then IC = 1 Else IC = 0 If LINK = 1 Then KE = 0 If LINK = 2 Then KI = 0 KI = KI + IC k = (KI * (JJJ - 1)) + (KE / JJJ) ReDim XY(1 To N, 1 To KI + KE), PES(1 To N) If NPES <> 0 Then NTPESM = Application.Average(R_XY.Rows.Columns(N PES)) NTPES = Application.Sum(R_XY.Rows.Columns(NPES)) / NTPESM Else NTPESM = 1 NTPES = N End If For i3 = 1 To N If NPES <> 0 Then PES(i3) = R_XY.Rows(i3).Colum ns(NPES) / NTPESM Else PES(i3) = 1 Next i3 If LINK <> 2 Then ReDim G2SWEEP(1 To KI + 1, 1 To KI + 1) For i3 = 1 To N If IC = 1 Then XY(i3, 1) = 1 For j1 = 1 To KI - IC XY(i3, IC + j1) = R_XY.Rows(i3).Columns( VAI(j1)) Next j1 For j1 = 1 To KI For k1 = j1 To KI G2SWEEP(j1, k1) = G2SWEEP(j1, k1) + (XY(i3, j1) * XY(i3, k1) * PES(i3)) Next k1 Next j1 Next i3 For j1 = 1 To KI For k1 = j1 + 1 To KI G2SWEEP(k1, j1) = G2SWEEP(j1, k1) Next k1 Next j1 ERROR_COMBINACIO = False Call C_G2SWEEP(0, IC, G2SWEEP, N, KI + 1, 0.0000 0001, ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide MsgBox "El modelo no es de rango completo.", vbCritical, TITOL Exit Sub End If End If If LINK <> 1 Then For i3 = 1 To N For j1 = 1 To KE XY(i3, j1 + KI) = R_XY.Rows(i3).Columns( VAE(j1)) Next j1 Next i3 End If '''''''''''''''''''''' 'Nomena les variables' '''''''''''''''''''''' ReDim LB(1 To k), LV(1 To k + 1) If LINK <> 2 Then For j1 = 1 To JJJ - 1 If IC = 1 Then LV((KI * (j1 - 1)) + 1) = "Const-" & Trim (Str(j1 - 1)) LB((KI * (j1 - 1)) + 1) = "b" & Trim(Str( (KI * (j1 - 1)) + 1)) End If For k1 = IC + 1 To KI LB((KI * (j1 - 1)) + k1) = "b" & Trim(St r((KI * (j1 - 1)) + k1)) If IX = 1 Then LV((KI * (j1 - 1)) + k1) = LVAR(VAI(k 1 - IC), 1) & "-" & Trim(Str(j1 - 1)) Else LV((KI * (j1 - 1)) + k1) = "AI" & Tri m(Str(k1 - IC)) & "-" & Trim(Str(j1 - 1)) End If Next k1 Next j1 If LINK = 1 Then If IX = 1 Then LV(k + 1) = LVAR(NE, 1) Else L V(k + 1) = "Y" End If End If

Page 151: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

150

If LINK <> 1 Then For j1 = 1 To (KE / JJJ) If IX = 1 Then LV(KI * (JJJ - 1) + j1) = Left(LVAR(VAE(j 1 * JJJ), 1), Len(LVAR(VAE(j1 * JJJ), 1)) - 1) Else LV(KI * (JJJ - 1) + j1) = "AE" & Trim(Str (j1)) End If LB(KI * (JJJ - 1) + j1) = "g" & Trim(Str(j1) ) Next j1 If IX = 1 Then LV(k + 1) = LVAR(NE, 1) Else LV(k + 1) = "Y" End If Call ANALISIS(1) End Sub Private Sub Cancelar_Click() SORTIR = True NPES = 0 Unload Me End Sub Private Sub ANALISIS(opcio As Integer) 'LOGIT MULT INOMIAL '''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul '''''''''''''''''''''''''''''''' Dim i1 As Integer ReDim OPT(1 To 6) For i1 = 1 To 6 OPT(i1) = True Next i1 CONVERG = Val(convergencia.Value) ITER = iteraciones.Value OPT(4) = restricciones.Value SIG = n_sig.Value Me.Hide End Sub Private Sub ATRIBUTOS(opcio As Integer) Dim i1 As Integer If opcio = 1 Or opcio = 3 Then AVIS_ATRIBUTOS_INDIVIDUALES = False For i1 = 1 To R_XY.Columns.Count If xs1.Selected(i1 - 1) Then AVIS_ATRIBUTOS_INDIVIDUALES = True Exit For End If Next i1 End If If opcio = 2 Or opcio = 3 Then AVIS_ATRIBUTOS_ELECCION = False For i1 = 1 To R_XY.Columns.Count If xs2.Selected(i1 - 1) Then AVIS_ATRIBUTOS_ELECCION = True Exit For End If Next i1 End If If AVIS_ATRIBUTOS_INDIVIDUALES Or AVIS_ATRIBUTOS_EL ECCION Then For Each CTL In Me.Controls CTL.Enabled = True Next CTL Else NPES = 0 For Each CTL In Me.Controls CTL.Enabled = False Next CTL Frame1.Enabled = True logitM.Enabled = True logitC.Enabled = True logitMC.Enabled = True Frame2.Enabled = True

Page 152: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

151

elecciones.Enabled = True Label1.Enabled = True If opcio = 1 Or opcio = 3 Then Label2.Enabled = True If opcio = 2 Or opcio = 3 Then Label3.Enabled = True ys.Enabled = True If opcio = 1 Or opcio = 3 Then xs1.Enabled = Tru e If opcio = 2 Or opcio = 3 Then xs2.Enabled = Tru e For i1 = 1 To R_XY.Columns.Count ps.Selected(i1 - 1) = False Next i1 Cancelar.Enabled = True End If End Sub Private Sub logitM_Click() If logitM Then LINK = 1 With Me .Label1.Left = 55 .Label2.Left = 150 .Label2.Visible = True .Label3.Visible = False .Label4.Left = 245 .Label4.Visible = True .ys.Left = 55 .xs1.Left = 150 .xs1.Visible = True .xs2.Visible = False .ps.Left = 245 .ps.Visible = True End With End If End Sub Private Sub logitC_Click() If logitC Then LINK = 2 With Me .Label1.Left = 55 .Label2.Visible = False .Label3.Left = 150 .Label3.Visible = True .Label4.Left = 245 .Label4.Visible = True .ys.Left = 55 .xs1.Visible = False .xs2.Left = 150 .xs2.Visible = True .ps.Left = 245 .ps.Visible = True End With End If End Sub Private Sub logitMC_Click() If logitMC Then LINK = 3 With Me .Label1.Left = 5 .Label2.Left = 100 .Label2.Visible = True .Label3.Left = 195 .Label3.Visible = True .Label4.Left = 290 .Label4.Visible = True .ys.Left = 5 .xs1.Left = 100 .xs1.Visible = True .xs2.Left = 195 .xs2.Visible = True .ps.Left = 290 .ps.Visible = True End With End If End Sub Private Sub UserForm_Layout() n_sig.Move Height:=12, Left:=195, Top:=65, Width:=4 0

Page 153: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

152

End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() If logitM Then Label2.Enabled = True xs1.Enabled = True End If If logitC Then Label3.Enabled = True xs2.Enabled = True End If If logitMC Then Label2.Enabled = True Label3.Enabled = True xs1.Enabled = True xs2.Enabled = True End If End Sub Private Sub xs1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If logitM Then Call ATRIBUTOS(1) If logitMC Then Call ATRIBUTOS(3) End Sub Private Sub xs2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single) If logitC Then Call ATRIBUTOS(2) If logitMC Then Call ATRIBUTOS(3) End Sub

Page 154: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

153

Attribute VB_Name = "M5" Option Explicit Public JJJ As Integer, KE As Integer, KI As Integer , LB() As String, LV() As String, _ NE As Integer, VAE() As Integer, VAI() As In teger Sub M5_(opcio As Integer) ''''''''''''''''''' 'LOGIT MULTINOMIAL' ''''''''''''''''''' '''''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' '''''''''''''''''''''''''''''''''''''' 'OPT(1) informació general (M5_01)' 'OPT(2) informació ajustament (M5_02)' 'OPT(3) contrasts MV,W i ML (M5_03)' 'OPT(4) restricciones (M5_04)' 'OPT(5) estimació (M5_05)' 'OPT(6) matriu variances ' '''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria4: Mod elos Logit y Probit' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String, vconv(12 ) As String, velec(7) As Integer, viter(49) As Inte ger, vsig(5) As Double For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 For i1 = 0 To 12 vconv(i1) = "1E-" & IIf(i1 < 7, 0, "") & i1 + 3 Next i1 For i1 = 8 To 1 Step -1 velec(8 - i1) = i1 Next i1 For i1 = 50 To 1 Step -1 viter(50 - i1) = i1 Next i1 For i1 = 5 To 0 Step -1 If i1 > 0 Then vsig(5 - i1) = 0.05 * i1 Else vs ig(5 - i1) = 0.01 Next i1 TITOL = "MicroEconometría: Modelo Logit multinomial " h = Application.min(110, 11 * R_XY.Columns.Count) With M5_LogitM .logitM.Value = True .elecciones.List = velec .elecciones.Selected(4) = True .ys.Move Height:=h, Top:=65, Width:=90 .ys.List = v .xs1.Move Height:=h, Top:=65, Width:=90 .xs1.List = v .xs2.Move Height:=h, Top:=65, Width:=90 .xs2.List = v .ps.Move Height:=h, Top:=65, Width:=90 .ps.List = v .convergencia.List = vconv .convergencia.Selected(5) = True .iteraciones.List = viter .iteraciones.Selected(25) = True .n_sig.List = vsig .n_sig.Selected(4) = True End With ERR_LEC = True SORTIR = False Do While ERR_LEC = True M5_LogitM.Show If SORTIR Then ERR_LEC = False Loop Unload M5_LogitM If SORTIR Then Exit Sub Dim avis As Boolean, it As Integer, lh() As Double, prop() As Double Call M5_SCORING(avis, it, lh, prop)

Page 155: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

154

If OPT(1) Then Call M5_01(avis, it, lh, prop) If OPT(2) Then Call M5_02(lh) If OPT(3) Then Call M5_03(avis, lh, prop) If OPT(4) Then Call M5_04(avis) If OPT(5) Then Call M5_05(avis) If OPT(6) And k > 1 Then Call M5_ESCRIPTURA_1(avis) INOU = INOU + 1 End Sub Private Sub M5_SCORING(avis, it, lh, prop) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''' 'Algoritme de càlcul, métode "SCORING" del LogitMul tinomial' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''' Dim c As Double, i3 As Long, j1 As Integer, k1 As I nteger, l1 As Integer, _ m1 As Integer, se As Double ReDim B(1 To k), g_d(1 To 2 * k) As Double, lh(2), MCOV(1 To k, 1 To k), p(1 To JJJ), _ prop(1 To JJJ, 1 To 2), X(1 To JJJ, 1 To k) A s Double c = 1 m1 = KI * (JJJ - 1) For j1 = 1 To k B(j1) = 0 Next j1 For it = 1 To ITER lh(1) = 0 ReDim MCOV(1 To k + 1, 1 To k + 1) As Double For i3 = 1 To N ReDim E(1 To JJJ) As Double, xm(1 To k) As Double If LINK <> 2 Then For j1 = 1 To JJJ - 1 For k1 = 1 To KI l1 = (KI * (j1 - 1)) + k1 E(j1) = E(j1) + (B(l1) * XY(i3, k1)) Next k1 Next j1 E(JJJ) = 0 End If If LINK <> 1 Then For j1 = 1 To JJJ For k1 = 1 To KE / JJJ l1 = j1 + ((k1 - 1) * JJJ) E(j1) = E(j1) + (B(k1 + m1) * XY (i3, l1 + KI)) Next k1 Next j1 End If se = 0 For j1 = 1 To JJJ E(j1) = Exp(E(j1)) se = se + E(j1) Next j1 For j1 = 1 To JJJ p(j1) = E(j1) / se If R_XY.Rows(i3).Columns(NE) + 1 = j1 T hen lh(1) = lh(1) + (Log(p(j1)) * PES(i3)) Next j1 If LINK <> 2 Then For j1 = 1 To JJJ - 1 For k1 = 1 To KI l1 = (KI * (j1 - 1)) + k1 xm(l1) = xm(l1) + (p(j1) * XY(i3 , k1)) Next k1 Next j1 For j1 = 1 To JJJ For k1 = 1 To m1 X(j1, k1) = -xm(k1) Next k1 For k1 = 1 To KI l1 = (KI * (j1 - 1)) + k1 If l1 > m1 Then Exit For X(j1, l1) = XY(i3, k1) - xm(l1) Next k1 Next j1 End If If LINK <> 1 Then For j1 = 1 To KE / JJJ For k1 = 1 To JJJ l1 = k1 + ((j1 - 1) * JJJ) xm(j1 + m1) = xm(j1 + m1) + (p(k 1) * XY(i3, l1 + KI)) Next k1 For k1 = 1 To JJJ l1 = k1 + ((j1 - 1) * JJJ)

Page 156: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

155

X(k1, j1 + m1) = XY(i3, l1 + KI) - xm(j1 + m1) Next k1 Next j1 End If For j1 = 1 To k For l1 = 1 To JJJ For k1 = j1 To k MCOV(j1, k1) = MCOV(j1, k1) + ( X(l1, k1) * p(l1) * X(l1, j1) * PES(i3)) Next k1 If R_XY.Rows(i3).Columns(NE) + 1 = l1 Then MCOV(j1, k + 1) = MCOV(j1, k + 1) + (X(l1, j1) * PES(i3)) Next l1 Next j1 Next i3 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 MCOV(k1, j1) = MCOV(j1, k1) Next k1 If j1 < k + 1 Then g_d(j1) = MCOV(j1, k + 1) Next j1 Call C_G2SWEEP(1, IC, MCOV, N, k + 1, 0.00000001 , False) For j1 = 1 To k B(j1) = B(j1) + MCOV(j1, k + 1) g_d(k + j1) = MCOV(j1, k + 1) Next j1 c = Application.max(Abs(lh(2) - lh(1)), Applicat ion.SumSq(g_d)) lh(2) = lh(1) If c <= CONVERG Then avis = True Exit For End If Next it it = it - 1 For j1 = 1 To JJJ For i3 = 1 To N If R_XY.Rows(i3).Columns(NE) = j1 - 1 Then prop(j1, 1) = prop(j1, 1) + 1 prop(j1, 2) = prop(j1, 2) + PES(i3) End If Next i3 Next j1 If LINK = 2 Then lh(0) = NTPES * Log(1 / JJJ) Else If IC = 1 Then For j1 = 1 To JJJ lh(0) = lh(0) + (prop(j1, 2) * Log(prop(j 1, 2) / NTPES)) Next j1 Else lh(0) = NTPES * Log(1 / JJJ) End If End If End Sub Private Sub M5_01(avis, it, lh, prop) '''''''''''''''''''''''''''''''''''''''''''' 'Escriptura de la informació de l'estimació' '''''''''''''''''''''''''''''''''''''''''''' Dim i1 As Integer, j1 As Integer ReDim R(1 To 7 + JJJ + IIf(NPES <> 0, JJJ + 1, 0), 1 To 4) R(1, 1) = "Modelo de probabilidad" R(1, 3) = "LOGIT " & IIf(LINK = 1, "MULTINOMIAL", I If(LINK = 2, "CONDICIONAL", "MIXTO")) R(2, 1) = "Técnica de optimización" R(2, 3) = "''Scoring' (Fisher)" R(3, 1) = "Variable cualitativa" R(3, 3) = LV(k + 1) For i1 = 1 To JJJ j1 = IIf(NPES <> 0, 2 * (i1 - 1) + 1, i1) R(j1 + 3, 1) = "Observaciones (" & LV(k + 1) & " = " & i1 - 1 & ")" R(j1 + 3, 3) = prop(i1, 1) If NPES <> 0 Then R(j1 + 4, 1) = "Observ. pond. (" & LV(k + 1) & " = " & i1 - 1 & ")" R(j1 + 4, 3) = prop(i1, 2) End If Next i1 R(4 + JJJ + IIf(NPES <> 0, JJJ, 0), 1) = "Observaci ones totales" R(4 + JJJ + IIf(NPES <> 0, JJJ, 0), 3) = NTPES R(5 + JJJ + IIf(NPES <> 0, JJJ, 0), 1) = "Iteracion es efectuadas"

Page 157: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

156

R(5 + JJJ + IIf(NPES <> 0, JJJ, 0), 3) = it R(6 + JJJ + IIf(NPES <> 0, JJJ, 0), 1) = "Criterio de convergencia" If avis Then R(6 + JJJ + IIf(NPES <> 0, JJJ, 0), 3) = CONVERG Else R(6 + JJJ + IIf(NPES <> 0, JJJ, 0), 3) = CONVERG & " No alcanzado!!!" R(7 + JJJ + IIf(NPES <> 0, JJJ, 0), 1) = "Log. L" R(7 + JJJ + IIf(NPES <> 0, JJJ, 0), 3) = lh(1) If NPES <> 0 Then R(8 + JJJ + IIf(NPES <> 0, JJJ, 0), 1) = "Variab le de ponderación" R(8 + JJJ + IIf(NPES <> 0, JJJ, 0), 3) = LVAR(NP ES, 1) End If Call M5_ESCRIPTURA(1, "Información general de la es timación", False) End Sub Private Sub M5_02(lh) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' 'Escriptura dels criteris d'informació de l'ajustam ent' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' ReDim aux(1 To 2) As String, R(1 To 6, 1 To 3) aux(1) = IIf(IC = 1, "Sólo" & Chr(10) & "Constantes ", "Sin" & Chr(10) & "parámetros") aux(2) = "Con todos los" & Chr(10) & "parámetros" R(1, 1) = "Criterio" R(1, 2) = aux(1) R(1, 3) = aux(2) R(3, 1) = "AIC" R(4, 1) = "Schwarz" R(5, 1) = "-2 log L" R(3, 2) = -2 * lh(0) + Log(NTPES) * (IC * (JJJ - 1) ) R(4, 2) = -2 * lh(0) + 2 * (IC * (JJJ - 1)) R(5, 2) = -2 * lh(0) R(3, 3) = -2 * lh(1) + Log(NTPES) * k R(4, 3) = -2 * lh(1) + 2 * k R(5, 3) = -2 * lh(1) R(6, 1) = "pseudo-R" & Chr(178) R(6, 2) = 1 - (lh(1) / lh(0)) Call M5_ESCRIPTURA(2, "Criterios de información del ajuste", False) End Sub Private Sub M5_03(avis, lh, prop) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' 'Càlcul i escriptura del test Raó de Versemblança, Score i Wald' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' Dim auxm() As Double, i1 As Integer, i3 As Long, j1 As Integer, k1 As Integer, l1 As Integer, m1 As In teger, _ test(1 To 3) As Double test(1) = -2 * (lh(0) - lh(1)) ReDim auxm(1 To k + 1, 1 To k + 1), G(1 To k) As Do uble, p(1 To JJJ) As Double, X(1 To JJJ, 1 To k) As Double m1 = KI * (JJJ - 1) For i3 = 1 To N ReDim xm(1 To k) As Double If LINK <> 2 Then For j1 = 1 To JJJ If IC = 1 Then p(j1) = prop(j1, 1) / N E lse p(j1) = 1 / JJJ Next j1 For j1 = 1 To JJJ - 1 For k1 = 1 To KI l1 = KI * (j1 - 1) + k1 xm(l1) = xm(l1) + (p(j1) * XY(i3, k1 )) Next k1 Next j1 For j1 = 1 To JJJ For k1 = 1 To m1 X(j1, k1) = -xm(k1) Next k1 For k1 = 1 To KI l1 = KI * (j1 - 1) + k1 If l1 > m1 Then Exit For X(j1, l1) = XY(i3, k1) - xm(l1) Next k1 Next j1 End If If LINK <> 1 Then For j1 = 1 To KE / JJJ For k1 = 1 To JJJ l1 = k1 + (j1 - 1) * JJJ xm(j1 + m1) = xm(j1 + m1) + (XY(i3, l1 + KI) / JJJ) Next k1 For k1 = 1 To JJJ

Page 158: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

157

l1 = k1 + (j1 - 1) * JJJ X(k1, j1 + m1) = XY(i3, l1 + KI) - x m(j1 + m1) Next k1 Next j1 End If For j1 = 1 To k For l1 = 1 To JJJ For k1 = j1 To k auxm(j1, k1) = auxm(j1, k1) + (X(l1 , k1) * X(l1, j1) * PES(i3) / JJJ) Next k1 If R_XY.Columns(NE).Rows(i3) + 1 = l1 T hen G(j1) = G(j1) + (X(l1, j1) * PES(i3)) Next l1 Next j1 Next i3 For j1 = 1 To k For k1 = j1 + 1 To k auxm(k1, j1) = auxm(j1, k1) Next k1 Next j1 Call C_G2SWEEP(1, IC, auxm, N, k + 1, 0.00000001, F alse) For j1 = 1 To k For k1 = 1 To k test(2) = test(2) + (G(k1) * auxm(j1, k1) * G(j1)) Next k1 Next j1 m1 = k - (IC * (JJJ - 1)) k1 = 0 l1 = 0 ReDim auxm(1 To m1 + 1, 1 To m1 + 1), VARS(1 To m1) If LINK <> 2 Then For i1 = 1 To JJJ - 1 For j1 = IC + 1 To KI k1 = k1 + 1 l1 = KI * (i1 - 1) + j1 VARS(k1) = l1 Next j1 Next i1 End If If LINK <> 1 Then For i1 = 1 To KE / JJJ VARS(i1 + k1) = i1 + l1 Next i1 End If For i1 = 1 To m1 For j1 = 1 To m1 auxm(i1, j1) = MCOV(VARS(i1), VARS(j1)) Next j1 Next i1 Call C_G2SWEEP(1, IC, auxm, N, m1 + 1, 0.00000001, False) For i1 = 1 To m1 For j1 = 1 To m1 test(3) = test(3) + (B(VARS(i1)) * auxm(i1, j1) * B(VARS(j1))) Next j1 Next i1 ReDim R(1 To 4, 1 To 4) R(1, 1) = "Test" R(1, 2) = "Valor c" & Chr(178) R(1, 3) = "gl" R(1, 4) = "Prob > c" & Chr(178) R(2, 1) = "Rat. verosim." R(3, 1) = "''Score'" R(4, 1) = "Wald" For i1 = 1 To 3 R(i1 + 1, 2) = test(i1) R(i1 + 1, 3) = m1 R(i1 + 1, 4) = Application.ChiDist(test(i1), m1 ) R(i1 + 1, 4) = IIf(R(i1 + 1, 4) < 0.0001, "< 0, 0001", R(i1 + 1, 4)) Next i1 avis = True If OPT(4) Then avis = False If UBound(MCOV, 1) <= 14 Then avis = False Call M5_ESCRIPTURA(3, "Hipótesis nula: pendiente" & IIf(k = 1, "=0", "(s)=0"), avis) End Sub Private Sub M5_04(avis) '''''''''''''''''''''' 'Restriccions lineals' '''''''''''''''''''''' Dim aux(1 To 2) As Double, a1() As Double, a2() As Double, a3() As Double, a4() As Boolean, _

Page 159: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

158

glr() As Integer, irest As Integer, i1 As Integ er, i2 As Integer, n_r() As String, _ w() As Double Call C_RESTRICCIONES_1(LINK + 1, MCOV, a1, a2, a3, a4, w, glr, irest, n_r) If SORTIR Then SORTIR = False If irest <= 1 Then Exit Sub Else irest = irest - 1 End If '''''''''''''''''''''''''''''''''''''''''''''''''' 'Calcula l'amplada de columna per a la restricció' '''''''''''''''''''''''''''''''''''''''''''''''''' aux(1) = 0 For i1 = 1 To irest If Len(n_r(i1)) > aux(1) Then i2 = i1 aux(1) = Len(n_r(i1)) End If Next i1 With Cells(1, 11) aux(2) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = n_r(i2) .Columns.AutoFit aux(1) = .ColumnWidth .Clear .ColumnWidth = aux(2) End With For i1 = 5 To 0 Step -1 If aux(1) > i1 * 9.57 Then Exit For Next i1 aux(2) = Application.max(i1 + 1, 1) ReDim R(1 To irest + 1, 1 To aux(2) + 3) R(1, 1) = "Restricción" R(1, aux(2) + 1) = "Valor c" & Chr(178) R(1, aux(2) + 2) = "gl" R(1, aux(2) + 3) = "Prob > c" & Chr(178) For i1 = 1 To irest R(i1 + 1, 1) = n_r(i1) R(i1 + 1, aux(2) + 1) = w(i1) R(i1 + 1, aux(2) + 2) = glr(i1) R(i1 + 1, aux(2) + 3) = Application.ChiDist(w(i 1), glr(i1)) R(i1 + 1, aux(2) + 3) = IIf(R(i1 + 1, aux(2) + 3) < 0.0001, "< 0,0001", R(i1 + 1, aux(2) + 3)) Next i1 avis = True If UBound(MCOV, 1) <= 14 Then avis = False Call M5_ESCRIPTURA(4, "Restricciones lineales (Test de Wald)", avis) End Sub Private Sub M5_05(avis) ''''''''''''''''''''''''''' 'Escriptura de l'estimació' ''''''''''''''''''''''''''' Dim aux As Double, i1 As Integer, lletra As String * 3 ReDim R(1 To k + 2, 1 To 7) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "Error" & Chr(10) & "Estándar" R(1, 4) = "Valor c" & Chr(178) R(1, 5) = "Prob > c" & Chr(178) R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" If SIG = 0.01 Then aux = 2.575834515 ElseIf SIG = 0.05 Then aux = 1.959961082 ElseIf SIG = 0.1 Then aux = 1.644853 ElseIf SIG = 0.15 Then aux = 1.439530024 ElseIf SIG = 0.2 Then aux = 1.281550794 ElseIf SIG = 0.25 Then aux = 1.150349362 End If

Page 160: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

159

For i1 = 1 To k R(i1 + 2, 1) = LB(i1) & "(" & LV(i1) & ")" R(i1 + 2, 2) = B(i1) R(i1 + 2, 3) = Sqr(MCOV(i1, i1)) R(i1 + 2, 4) = (R(i1 + 2, 2) / R(i1 + 2, 3)) ^ 2 R(i1 + 2, 5) = Application.ChiDist(R(i1 + 2, 4) , 1) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0, 0001", R(i1 + 2, 5)) R(i1 + 2, 6) = B(i1) - (aux * R(i1 + 2, 3)) R(i1 + 2, 7) = B(i1) + (aux * R(i1 + 2, 3)) Next i1 avis = True If k <= 36 Then avis = False Else avis = True Call M5_ESCRIPTURA(5, "Resultados de la estimación" , avis) End Sub Private Sub M5_ESCRIPTURA_1(avis) '''''''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A L'ESCRIPTURA DE MATRIUS' '''''''''''''''''''''''''''''''''''''''' Dim i1 As Integer, i2 As Integer, j1 As Integer, j2 As Integer Dim dim1 As Integer, dim2 As Integer, maxim2 As Int eger, resta2 As Integer dim1 = UBound(MCOV, 1) - 1 dim2 = IIf(dim1 <= 9, dim1, 9) maxim2 = IIf(dim1 <= 9, 1, Int(dim1 / 9)) resta2 = IIf(dim1 <= 9, 0, dim1 - (maxim2 * 9)) If resta2 <> 0 Then maxim2 = maxim2 + 1 For j1 = 1 To maxim2 ReDim R(1 To dim1 + 1, 1 To IIf(j1 < maxim2, di m2, IIf(j1 = 1, dim2, IIf(resta2 <> 0, resta2, dim2 ))) + 1) For j2 = 1 To IIf(j1 < maxim2, dim2, IIf(j1 = 1 , dim2, IIf(resta2 <> 0, resta2, dim2))) i2 = j2 + ((j1 - 1) * 9) R(1, j2 + 1) = LB(i2) & "(" & LV(i2) & ")" Next j2 For i1 = 1 To dim1 R(i1 + 1, 1) = LB(i1) & "(" & LV(i1) & ")" For j2 = 1 To IIf(j1 < maxim2, dim2, IIf(j1 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) R(i1 + 1, j2 + 1) = MCOV(i1, j2 + ((j1 - 1) * 9)) Next j2 Next i1 If dim1 <= 9 Then avis = True ElseIf dim1 <= 18 Then avis = IIf(j1 = 2, True, False) ElseIf dim1 <= 27 Then avis = IIf(j1 = 1 Or j1 = 3, True, False) ElseIf dim1 <= 36 Then avis = IIf(j1 = 2, False, True) Else avis = True End If Call M5_ESCRIPTURA(6, "Matriz de varianzas y co varianzas" & IIf(j1 = 1, "", "(cont.)"), avis) Next j1 End Sub Private Sub M5_ESCRIPTURA(opcio As Integer, TITOL A s String, avis) '''''''''''''''''''' 'Escriptura general' '''''''''''''''''''' Sheets(FULL_R).Activate ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' 'opcio=1 ==> Informació general de l'estimació ' 'opcio=2 ==> Criteris d'informació de l'ajustament ' 'opcio=3 ==> Test Raó de Versemblança, Multiplicado rs de Lagrange i Wald' 'opcio=4 ==> Restriccions lineals ' 'opcio=5 ==> Estimació ' 'opcio=6 ==> Matriu de variàncies i covariàncies ' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' Dim c(1 To 2) As Integer, i1 As Integer, j1 As Inte ger, k1 As Integer c(1) = UBound(R, 1) c(2) = UBound(R, 2) With Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 10) ) .ColumnWidth = 9.5 With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter

Page 161: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

160

.Interior.ColorIndex = 2 .RowHeight = 11 .VerticalAlignment = xlCenter End With With Cells(F - 1, 1) .Font.Bold = True .HorizontalAlignment = xlLeft .Value = TITOL End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) .Borders(xlEdgeTop).LineStyle = xlDouble .Borders(xlEdgeBottom).LineStyle = xlDouble .Interior.ColorIndex = 37 .Value = R End With With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Font.Bold = True .HorizontalAlignment = xlLeft End With If opcio <> 1 Then i1 = IIf(opcio = 2 Or opcio = 5, 1, 0) For j1 = 1 To c(2) With Range(Cells(F, j1), Cells(F + i1, j1)) .Borders(xlEdgeBottom).LineStyle = xlConti nuous .Font.Bold = True .MergeCells = True .WrapText = True End With Next j1 End If If opcio = 1 Then For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , 2)).MergeCells = True Range(Cells(F + i1 - 1, 3), Cells(F + i1 - 1 , 4)).MergeCells = True With Cells(F + i1 - 1, 3) .HorizontalAlignment = xlLeft If i1 > 3 And i1 <= 5 + JJJ + IIf(NPES <> 0, JJJ, 0) Then .NumberFormat = "###,0" If i1 = 6 + JJJ + IIf(NPES <> 0, JJJ, 0) T hen .NumberFormat = "0.00E+00" If i1 = IIf(NPES <> 0, 7 + JJJ + JJJ, 7 + JJJ) Then If Abs(R(i1, 3)) >= 1000 And Abs(R(i1, 3)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, 3)) < 1000 And Abs(R(i1, 3 )) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End If End With Next i1 ElseIf opcio = 2 Then Range(Cells(F, 2), Cells(F + c(1), c(2))).Number Format = "###,0.000" Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeTop).LineStyle = xlContinuou s Cells(F + c(1) - 1, 2).NumberFormat = "0.0000" Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , 2)).VerticalAlignment = xlCenter ElseIf opcio = 3 Or opcio = 4 Then For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , c(2) - 3)).MergeCells = True Next i1 If opcio = 4 Then For i1 = 2 To c(1) With Cells(F + i1 - 1, 1) For j1 = 1 To Len(R(i1, 1)) If Mid(R(i1, 1), j1, 1) = "b" Or Mi d(R(i1, 1), j1, 1) = "g" Then .Characters(j1, 1).Fo nt.Name = "Symbol" If Mid(R(i1, 1), j1, 1) = "b" Or Mi d(R(i1, 1), j1, 1) = "g" Then .Characters(j1, 1).Fo nt.Bold = True Next j1 End With Next i1 End If Cells(F, c(2) - 2).Characters(8, 1).Font.Name = "symbol" Cells(F, c(2) - 2).Characters(8, 1).Font.Bold = True Cells(F, c(2)).Characters(8, 1).Font.Name = "sym bol" Cells(F, c(2)).Characters(8, 1).Font.Bold = True For j1 = c(2) - 2 To c(2) With Range(Cells(F, j1), Cells(F + c(1), j1) ) If j1 = c(2) - 2 Then .NumberFormat = "### ,0.000" If j1 = c(2) - 1 Then .NumberFormat = "0" If j1 = c(2) Then .NumberFormat = "0.0000" End With Next j1 ElseIf opcio = 5 Then Range(Cells(F, 6), Cells(F + 1, 7)).MergeCells = True Range(Cells(F, 9), Cells(F + 1, 10)).MergeCells = True Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1) .Font.Name = "symbol" Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1) .Font.Bold = True Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Name = "symbol"

Page 162: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

161

Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Bold = True Range(Cells(F + 2, 4), Cells(F + c(1) - 1, 4)).N umberFormat = "###,0.000" Range(Cells(F + 2, 5), Cells(F + c(1) - 1, 5)).N umberFormat = "0.0000" If LINK = 3 Then i1 = F + KI * (JJJ - 1) + 2 Range(Cells(i1, 1), Cells(i1, c(2))).Borders( xlTop).LineStyle = xlDash End If For i1 = 2 To c(1) For j1 = 2 To 3 With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R(i1 , 3)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, j1)) < 1000 And Abs(R(i1, 3)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End With Next j1 For j1 = 6 To 7 With Cells(F + i1 - 1, j1) If Abs(R(i1, 3)) >= 1000 And Abs(R(i1, 3)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, 3)) < 1000 And Abs(R(i1, 3)) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End With Next j1 Next i1 ElseIf opcio = 6 Then Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Borde rs(xlRight).LineStyle = xlContinuous For i1 = 2 To c(1) Cells(F + i1 - 1, 1).Characters(1, 1).Font.N ame = "symbol" Cells(F + i1 - 1, 1).Characters(1, 1).Font.B old = True Cells(F, i1).Characters(1, 1).Font.Name = "s ymbol" Cells(F, i1).Characters(1, 1).Font.Bold = Tr ue Next i1 If LINK = 3 Then i1 = F + KI * (JJJ - 1) + 1 Range(Cells(i1, 1), Cells(i1, c(2))).Borders( xlTop).LineStyle = xlDash For j1 = 2 To c(2) If Left(R(1, j1), 3) = "g1(" Then Range(Cells(F, j1), Cells(F + c(1) - 1 , j1)).Borders(xlLeft).LineStyle = xlDash Exit For End If Next j1 End If End If If avis Then ActiveWindow.SelectedSheets.HPageBreak s.Add (Cells(F + c(1), 1)) F = F + c(1) + 2 Sheets(FULL).Activate End Sub

Page 163: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

162

Attribute VB_Name = "M6_CountData" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVISEXOGENES As Boolean Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Long, nobs ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then NY = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable endógena.", vbCritical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VX(1 To i2) VX(i2) = i1 NX = i2 ERR_LEC = False End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar al menos una variable e xógena.", vbCritical, TITOL Exit Sub End If NPES = 0 For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 For i1 = 1 To NX If NY = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y exógena.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If NY = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(NY, 1) & " no puede ser endógena y factor de elevación.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If NPES = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(VX(i1), 1) & " no puede ser e xógena y factor de elevación.", vbCritical, TITOL Exit Sub End If Next i1 End If O = 0 For i1 = 1 To R_XY.Columns.Count If x_offset.Selected(i1 - 1) Then O = i1 Exit For End If Next i1 If O <> 0 Then If O = NY Then ERR_LEC = True

Page 164: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

163

Me.Hide MsgBox LVAR(O, 1) & " no puede ser variable ' offset' y endógena.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If O = VX(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(O, 1) & " no puede ser variab le 'offset' y exógena.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If O = NPES Then ERR_LEC = True Me.Hide MsgBox LVAR(O, 1) & " no puede ser variabl e 'offset' y factor de elevación.", vbCritical, TIT OL Exit Sub End If End If End If If Application.Count(R_XY.Columns(NY)) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(NY, 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If For i1 = 1 To NX If Application.Count(R_XY.Columns(VX(i1))) <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(V X(i1), 1) & " no es numérico.", vbCritical, TITOL Exit Sub End If Next i1 If NPES <> 0 Then If Application.Count(R_XY.Columns(NPES)) <> N Or Application.CountIf(R_XY.Columns(NPES), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N PES, 1) & " es negativo, nulo o no numérico.", vbCr itical, TITOL Exit Sub End If End If If Application.CountIf(R_XY.Columns(NY), ">=0") <> N Then ERR_LEC = True Me.Hide MsgBox "Algún valor de " & LVAR(NY, 1) & " es ne gativo.", vbCritical, TITOL Exit Sub End If If O <> 0 Then If Application.Count(R_XY.Columns(O)) <> N Or Ap plication.CountIf(R_XY.Columns(O), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de " & LVAR(O, 1) & " es negativo, nulo o no numérico.", vbCritical, TITOL Exit Sub End If End If If Constante.Value = True Then IC = 1 Else IC = 0 k = IC + NX ReDim G2SWEEP(1 To k + 1, 1 To k + 1), XY(1 To N, 1 To k + 1), PES(1 To N) If NPES <> 0 Then NTPESM = Application.Average(R_XY.Rows.Columns(N PES)) NTPES = Application.Sum(R_XY.Rows.Columns(NPES)) / NTPESM Else NTPESM = 1 NTPES = N End If For i3 = 1 To N If NPES <> 0 Then PES(i3) = R_XY.Rows(i3).Colum ns(NPES) / NTPESM Else PES(i3) = 1 If IC = 1 Then XY(i3, 1) = 1 For i1 = 1 To NX XY(i3, IC + i1) = R_XY.Rows(i3).Columns(VX( i1)) Next i1 XY(i3, k + 1) = R_XY.Rows(i3).Columns(NY) If XY(i3, k + 1) <> 0 Then XY(i3, k + 1) = Log( XY(i3, k + 1)) Else XY(i3, k + 1) = 0 If O <> 0 Then XY(i3, k + 1) = XY(i3, k + 1) - R_XY.Rows(i3).Columns(O) For i1 = 1 To k + 1 For i2 = i1 To k + 1

Page 165: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

164

G2SWEEP(i1, i2) = G2SWEEP(i1, i2) + (XY (i3, i1) * XY(i3, i2) * PES(i3)) Next i2 Next i1 Next i3 For i1 = 1 To k + 1 For i2 = i1 + 1 To k + 1 G2SWEEP(i2, i1) = G2SWEEP(i1, i2) Next i2 Next i1 ERROR_COMBINACIO = False Call C_G2SWEEP(0, IC, G2SWEEP, N, k + 1, 0.00000001 , ERROR_COMBINACIO) If ERROR_COMBINACIO Then ERR_LEC = True Me.Hide MsgBox "El modelo no es de rango completo.", vbC ritical, TITOL Exit Sub End If If IC = 1 Then LVAR(1, 2) = "Const." For i1 = 1 To NX LVAR(IC + i1, 2) = LVAR(VX(i1), 1) Next i1 LVAR(k + 1, 2) = LVAR(NY, 1) Call ANALISIS(1) End Sub Private Sub Cancelar_Click() SORTIR = True NPES = 0 Unload Me End Sub Private Sub ANALISIS(opcio As Integer) 'COUNT DATA '''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul '''''''''''''''''''''''''''''''' Dim i1 As Integer ReDim OPT(1 To 8) For i1 = 1 To 8 OPT(i1) = True Next i1 CONVERG = Val(convergencia.Value) ITER = iteraciones.Value OPT(5) = contrastes.Value OPT(6) = restricciones.Value If k - IC = 1 Then OPT(6) = False If O <> 0 Then LVAR(0, 2) = LVAR(O, 1) SIG = n_sig.Value Me.Hide End Sub Private Sub EXOGENES(opcio As Integer) Dim i1 As Integer AVISEXOGENES = False For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then AVISEXOGENES = True Exit For End If Next i1 If AVISEXOGENES Then For Each CTL In Me.Controls CTL.Enabled = True Next CTL Else NPES = 0 For Each CTL In Me.Controls CTL.Enabled = False Next CTL Label1.Enabled = True Label2.Enabled = True For i1 = 1 To R_XY.Columns.Count ps.Selected(i1 - 1) = False

Page 166: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

165

x_offset.Selected(i1 - 1) = False Next i1 ys.Enabled = True xs.Enabled = True End If End Sub Private Sub Constante_Click() If Constante Then contrastes.Enabled = True Else contrastes.Enabled = False contrastes.Value = False End If End Sub Private Sub ps_Click() Dim i1 As Integer For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 End Sub Private Sub UserForm_Layout() n_sig.Move Height:=12, Left:=210, Top:=65, Width:=4 0 End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() Label2.Enabled = True xs.Enabled = True End Sub Private Sub xs_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call EXOGENES(1) End Sub

Page 167: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

166

Attribute VB_Name = "M6" Option Explicit Public O As Integer Sub M6_(opcio As Integer) '''''''''''' 'COUNT DATA' '''''''''''' '''''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' '''''''''''''''''''''''''''''''''''''' 'OPT(1) informació general (M6_01)' 'OPT(2) informació ajustament (M6_02)' 'OPT(3) bondat ajustament (M6_03)' 'OPT(4) contrasts MV,W i ML (M6_04)' 'OPT(5) contrasts (M6_05)' 'OPT(6) restricciones (M6_06)' 'OPT(7) estimació (M6_07)' 'OPT(8) matriu variances ' '''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria6: Mod elo 'Count data' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String, vconv(12 ) As String, viter(49) As Integer, vsig(5) As Doubl e For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 For i1 = 0 To 12 vconv(i1) = "1E-" & IIf(i1 < 7, 0, "") & i1 + 3 Next i1 For i1 = 50 To 1 Step -1 viter(50 - i1) = i1 Next i1 For i1 = 5 To 0 Step -1 If i1 > 0 Then vsig(5 - i1) = 0.05 * i1 Else vs ig(5 - i1) = 0.01 Next i1 TITOL = "MicroEconometría: Modelo 'Count data'" h = Application.min(110, 11 * R_XY.Columns.Count) With M6_CountData .ys.Move Height:=h, Top:=30, Width:=90 .ys.List = v .xs.Move Height:=h, Top:=30, Width:=90 .xs.List = v .x_offset.Move Height:=h, Top:=30, Width:=90 .x_offset.List = v .ps.Move Height:=h, Top:=30, Width:=90 .ps.List = v .convergencia.List = vconv .convergencia.Selected(5) = True .iteraciones.List = viter .iteraciones.Selected(25) = True .n_sig.List = vsig .n_sig.Selected(4) = True End With ERR_LEC = True SORTIR = False Do While ERR_LEC = True M6_CountData.Show If SORTIR Then ERR_LEC = False Loop Unload M6_CountData If SORTIR Then Exit Sub Dim avis As Boolean, escala As Double, it As Intege r, lambda As Double, lh() As Double, vaux() As Doub le Call M6_SCORING(avis, escala, it, lh, vaux) If OPT(1) Then Call M6_01(avis, it, lh) If OPT(2) Then Call M6_02(lh) If OPT(3) Then Call M6_03(escala, lh, vaux) If OPT(4) Then Call M6_04(avis, lh, vaux) If OPT(5) Then Call M6_05(avis) If OPT(6) Then Call M6_06(avis)

Page 168: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

167

If OPT(7) Then Call M6_07(escala) If OPT(8) And k > 1 Then Call M6_ESCRIPTURA_1(1) INOU = INOU + 1 End Sub Private Sub M6_SCORING(avis, escala, it, lh, vaux) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' 'Algoritme de càlcul, métode "SCORING" del 'Count D ata' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' Dim aux As Double, c As Double, E1 As Double, i3 As Long, j1 As Integer, k1 As Integer, _ lambda As Double, z As Double ReDim B(1 To k), d_g(1 To 2 * k) As Double, lh(1), vaux(1 To 4) As Double For j1 = 1 To k B(j1) = G2SWEEP(j1, k + 1) Next j1 If O <> 0 Then vaux(2) = 0 Else vaux(2) = 1 vaux(3) = 0 For i3 = 1 To N XY(i3, k + 1) = R_XY.Rows(i3).Columns(NY) vaux(1) = vaux(1) + (XY(i3, k + 1) * PES(i3)) If O <> 0 Then vaux(2) = vaux(2) + (Exp(R_XY.Rows(i3).Colum ns(O)) * PES(i3)) vaux(3) = vaux(3) + (XY(i3, k + 1) * R_XY.Ro ws(i3).Columns(O) * PES(i3)) End If vaux(4) = vaux(4) + Log(Application.Fact(Applic ation.min(XY(i3, k + 1), 170))) Next i3 vaux(1) = vaux(1) / NTPES If O <> 0 Then vaux(2) = vaux(2) / NTPES c = 1 For it = 1 To ITER lh(1) = 0 ReDim MCOV(1 To k + 1, 1 To k + 1) For i3 = 1 To N If O <> 0 Then z = R_XY.Rows(i3).Columns(O) Else z = 0 For j1 = 1 To k z = z + (XY(i3, j1) * B(j1)) Next j1 lambda = Exp(z) E1 = XY(i3, k + 1) - lambda lh(1) = lh(1) + (((XY(i3, k + 1) * z) - lam bda) * PES(i3)) For j1 = 1 To k For k1 = j1 To k MCOV(j1, k1) = MCOV(j1, k1) + (XY(i 3, j1) * lambda * XY(i3, k1) * PES(i3)) Next k1 MCOV(j1, k + 1) = MCOV(j1, k + 1) + (E1 * XY(i3, j1) * PES(i3)) Next j1 Next i3 For j1 = 1 To k + 1 For k1 = j1 + 1 To k + 1 MCOV(k1, j1) = MCOV(j1, k1) Next k1 If j1 < k + 1 Then d_g(j1) = MCOV(j1, k + 1 ) Next j1 Call C_G2SWEEP(1, IC, MCOV, N, k + 1, 0.0000000 1, False) For j1 = 1 To k B(j1) = B(j1) + MCOV(j1, k + 1) d_g(k + j1) = MCOV(j1, k + 1) Next j1 c = Application.max(Abs(aux - lh(1)), Applicati on.SumSq(d_g)) aux = lh(1) If c <= CONVERG Then avis = True Exit For End If Next it it = it - 1 lh(1) = lh(1) - vaux(4) '''''''''''''''''''''''''''''''' 'Calcula la versemblança en ß=0' '''''''''''''''''''''''''''''''' If IC = 1 Then lh(0) = N * vaux(1) * (Log(vaux(1)) - Log(vaux(2 )) - 1) + vaux(3) - vaux(4) Else lh(0) = -(N * vaux(2)) + vaux(3) - vaux(4) End If

Page 169: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

168

End Sub Private Sub M6_01(avis, it, lh) '''''''''''''''''''''''''''''''''''''''''''' 'Escriptura de la informació de l'estimació' '''''''''''''''''''''''''''''''''''''''''''' Dim c As Integer If avis Then c = 0 Else c = 1 ReDim R(1 To 7 + IIf(O <> 0, 1, 0) + IIf(NPES <> 0, 1, 0), 1 To 3 + c) R(1, 1) = "Modelo de probabilidad" R(1, 3 + c) = "POISSON" R(2, 1) = "Técnica de optimización" R(2, 3 + c) = "''Scoring' (Fisher)" R(3, 1) = "Variable 'Count'" R(3, 3 + c) = LVAR(k + 1, 2) If O <> 0 Then R(4, 1) = "Variable 'OFFSET'" R(4, 3 + c) = LVAR(O, 1) End If R(4 + IIf(O <> 0, 1, 0), 1) = "Observaciones totale s" R(4 + IIf(O <> 0, 1, 0), 3 + c) = N R(5 + IIf(O <> 0, 1, 0), 1) = "Iteraciones efectuad as" R(5 + IIf(O <> 0, 1, 0), 3 + c) = it R(6 + IIf(O <> 0, 1, 0), 1) = "Criterio de converge ncia" R(6 + IIf(O <> 0, 1, 0), 3 + c) = CONVERG & IIf(avi s, "", " No alcanzado!!!") R(7 + IIf(O <> 0, 1, 0), 1) = "Log L" R(7 + IIf(O <> 0, 1, 0), 3 + c) = lh(1) If NPES <> 0 Then R(8 + IIf(O <> 0, 1, 0), 1) = "Variable de Ponde ración" R(8 + IIf(O <> 0, 1, 0), 3 + c) = LVAR(NPES, 1) End If Call M6_ESCRIPTURA(1, "Información general de la es timación", False) End Sub Private Sub M6_02(lh) ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' 'Escriptura dels criteris d'informació de l'ajustam ent' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''' ReDim s(1 To 2) As String, R(1 To 5, 1 To 3) s(1) = IIf(IC = 1, "Sólo" & Chr(10) & "Constante", "Sin" & Chr(10) & "parámetros") s(2) = "Con todos los" & Chr(10) & "parámetros" R(1, 1) = "Criterio" R(1, 2) = s(1) R(1, 3) = s(2) R(3, 1) = "AIC" R(4, 1) = "Schwarz" R(5, 1) = "-2 log L" R(3, 2) = -2 * lh(0) + 2 * IC R(4, 2) = -2 * lh(0) + Log(NTPES) * IC R(5, 2) = -2 * lh(0) R(3, 3) = -2 * lh(1) + 2 * k R(4, 3) = -2 * lh(1) + Log(NTPES) * k R(5, 3) = -2 * lh(1) Call M6_ESCRIPTURA(2, "Criterios de información del ajuste", False) End Sub Private Sub M6_03(escala, lh, vaux) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''' 'Càlcul i escriptura de les mesures de bondat de l' ajustament' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''' Dim i3 As Long, j1 As Integer, lambda As Double, z As Double ReDim aux(1 To IIf(IC = 1, 5, 1)) As Double, c(1 To IIf(IC = 1, 5, 3)) As Double, _ R(1 To IIf(IC = 1, 6, 4), 1 To 4) For i3 = 1 To N If O <> 0 Then z = R_XY.Rows(i3).Columns(O) Els e z = 0 For j1 = 1 To k z = z + (XY(i3, j1) * B(j1)) Next j1 lambda = Exp(z) If XY(i3, k + 1) = 0 Then aux(1) = -(XY(i3, k + 1) - lambda) If IC = 1 Then aux(2) = 0 Else aux(1) = XY(i3, k + 1) * Log(XY(i3, k + 1) / lambda) - (XY(i3, k + 1) - lambda) If IC = 1 Then aux(2) = XY(i3, k + 1) * Log( XY(i3, k + 1) * PES(i3) / vaux(1)) End If

Page 170: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

169

c(1) = c(1) + (aux(1) * PES(i3)) c(2) = c(2) + ((((XY(i3, k + 1) - lambda) ^ 2) / lambda) * PES(i3)) If IC = 1 Then aux(3) = aux(3) + ((((XY(i3, k + 1) * PES(i3 )) - vaux(1)) ^ 2) / vaux(1)) aux(4) = aux(4) + aux(1) aux(5) = aux(5) + aux(2) End If Next i3 c(1) = 2 * c(1) c(3) = 1 - (lh(1) / lh(0)) If IC = 1 Then c(4) = 1 - (c(2) / aux(3)) c(5) = 1 - (aux(4) / aux(5)) End If R(1, 1) = "Criterio" R(1, 2) = "Valor" R(1, 3) = "gl" R(1, 4) = "Valor/gl" R(2, 1) = "Desviación" R(3, 1) = "c" & Chr(178) & " de Pearson" R(4, 1) = "pseudo-R" & Chr(178) If IC = 1 Then R(5, 1) = "R" & Chr(178) & "(p)" R(6, 1) = "R" & Chr(178) & "(d)" End If For j1 = 1 To IIf(IC = 1, 5, 3) R(1 + j1, 2) = c(j1) Next j1 R(2, 3) = N - k R(3, 3) = N - k R(2, 4) = c(1) / (N - k) R(3, 4) = c(2) / (N - k) Call M6_ESCRIPTURA(3, "Medidas de bondad del ajuste ", False) escala = c(1) / (N - k) End Sub Private Sub M6_04(avis, lh, vaux) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' 'Càlcul i escriptura del test de Rao versemblança, Score i Wald' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''' Dim aux As Double, auxm() As Double, i3 As Integer, j1 As Integer, k1 As Integer, test(1 To 2) As Doub le test(1) = -2 * (lh(0) - lh(1)) ReDim auxm(1 To k - IC + 1, 1 To k - IC + 1) For j1 = 1 To k - IC For k1 = 1 To k - IC auxm(j1, k1) = MCOV(j1 + IC, k1 + IC) Next k1 Next j1 Call C_G2SWEEP(1, IC, auxm, N, k - IC + 1, 0.000000 01, False) For j1 = 1 To k - IC For k1 = 1 To k - IC test(2) = test(2) + (B(j1 + IC) * auxm(j1, k1) * B(k1 + IC)) Next k1 Next j1 'ReDim auxm(1 To K + 1, 1 To K + 1), g(1 To K) As D ouble 'Dim lambda As Double 'If O <> 0 Then lambda = IIf(IC = 1, vaux(1) / vaux (2), 1) Else lambda = IIf(IC = 1, vaux(1), 1) 'For i3 = 1 To N ' For j1 = 1 To K ' g(j1) = g(j1) + ((XY(i3, K + 1) - lambda) * XY(i3, j1) * PES(i3)) ' For k1 = j1 To K ' auxm(j1, k1) = auxm(j1, k1) + (XY(i3, j1) * ((XY(i3, K + 1) - lambda) ^ 2) * XY(i3, k1) * PES(i3)) ' Next k1 ' Next j1 'Next i3 'For j1 = 1 To K ' For k1 = j1 + 1 To K ' auxm(k1, j1) = auxm(j1, k1) ' Next k1 'Next j1 'Call C_G2SWEEP(1, IC, auxm, N, K + 1, 0.00000001, False) 'For j1 = 1 To K ' For k1 = 1 To K ' test(3) = test(3) + (g(j1) * auxm(j1, k1) * g(k1)) ' Next k1 'Next j1

Page 171: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

170

'ReDim auxm(1 To K + 1, 1 To K + 1), xy_(1 To K + 1 ) As Double 'Dim lambda As Double, vto As Double 'If O <> 0 Then lambda = IIf(IC = 1, vaux(1) / vaux (2), 1) Else lambda = IIf(IC = 1, vaux(1), 1) 'For i3 = 1 To N ' For j1 = 1 To K ' xy_(j1) = XY(i3, j1) * (XY(i3, K + 1) - la mbda) ' Next j1 ' xy_(K + 1) = 1 ' For j1 = 1 To K + 1 ' For k1 = j1 To K + 1 ' auxm(j1, k1) = auxm(j1, k1) + (xy_(j1) * xy_(k1) * PES(i3)) ' Next k1 ' Next j1 'Next i3 'For j1 = 1 To K + 1 ' For k1 = j1 + 1 To K + 1 ' auxm(k1, j1) = auxm(j1, k1) ' Next k1 'Next j1 'vto = auxm(K + 1, K + 1) 'Call C_G2SWEEP(1, IC, auxm, N, K + 1, 0.00000001, False) 'test(4) = N * (vto - auxm(K + 1, K + 1)) / vto ReDim R(1 To 3, 1 To 4) R(1, 1) = "Test" R(1, 2) = "Valor c" & Chr(178) R(1, 3) = "gl" R(1, 4) = "Prob > c" & Chr(178) R(2, 1) = "Ratio Verosim." R(3, 1) = "Wald" 'R(4, 1) = "'Score'(1)" 'R(5, 1) = "'Score'(2)" For j1 = 1 To 2 R(j1 + 1, 2) = test(j1) R(j1 + 1, 3) = k - IC R(j1 + 1, 4) = Application.ChiDist(test(j1), k - IC) R(j1 + 1, 4) = IIf(R(j1 + 1, 4) < 0.0001, "< 0, 0001", R(j1 + 1, 4)) Next j1 avis = True If OPT(5) Then avis = False If OPT(6) Then avis = False If UBound(MCOV, 1) <= 12 Then avis = False Call M6_ESCRIPTURA(4, "Hipótesis nula: Pendiente" & IIf(k = 1, "", "(s)") & "=0", avis) End Sub Private Sub M6_05(avis) ''''''''''''''''''''''''' 'Tests de especificación' ''''''''''''''''''''''''' Dim aux As Double, E1 As Double, i1 As Integer, i3 As Long, j1 As Integer, k1 As Integer, _ kk As Integer, lambda As Double, l1 As Integer, sqr_2 As Double, v As Double, z As Double kk = k + IIf(O <> 0, 1, 0) ReDim m11(1 To 2, 1 To 2) As Double, m21(1 To 2, 1 To 2) As Double, M31(1 To kk - 1) As Double, _ m32(1 To kk + 1, 1 To kk + 1) As Double, m33( 1 To kk - 1, 1 To kk) As Double, _ m34(1 To kk - 1, 1 To kk - 1) As Double, m35( 1 To kk - 1, 1 To kk - 1) As Double, _ m36(1 To kk, 1 To kk) As Double, s4(1 To 2) A s Double, s5(1 To 2) As Double, _ test(1 To 4) As Double, xy_(1 To kk) As Doubl e sqr_2 = Sqr(2) For i3 = 1 To N z = 0 If O <> 0 Then z = R_XY.Rows(i3).Columns(O) For j1 = 1 To k z = z + (XY(i3, j1) * B(j1)) Next j1 lambda = Exp(z) E1 = XY(i3, k + 1) - lambda xy_(2) = ((E1 ^ 2) - XY(i3, k + 1)) / (lambda * sqr_2) For l1 = 1 To 2 xy_(1) = IIf(l1 = 1, 1, lambda) For j1 = 1 To 2 For k1 = 1 To 2 If l1 = 1 Then m11(j1, k1) = m11(j1 , k1) + (xy_(j1) * xy_(k1)) If l1 = 2 Then m21(j1, k1) = m21(j1 , k1) + (xy_(j1) * xy_(k1)) Next k1 Next j1 Next l1 v = (E1 ^ 2) - lambda For j1 = 1 To k xy_(j1) = XY(i3, j1) Next j1

Page 172: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

171

If O <> 0 Then xy_(kk) = R_XY.Rows(i3).Columns( O) For j1 = 1 To kk If j1 > 1 Then M31(j1 - 1) = M31(j1 - 1) + (v * xy_(j1)) For k1 = 1 To kk m32(j1, k1) = m32(j1, k1) + (xy_(j1) * (E1 ^ 2) * xy_(k1)) If j1 > 1 Then m33(j1 - 1, k1) = m33(j1 - 1, k1) + (xy_(j1) * (v * E1) * xy_(k1)) If k1 > 1 Then m34(j1 - 1, k1 - 1) = m34(j1 - 1, k1 - 1) + (xy_(j1) * (v ^ 2) * xy_(k1) ) End If Next k1 Next j1 s4(1) = s4(1) + (E1 ^ 2) s4(2) = s4(2) + (lambda ^ 2) aux = 0.5 * Log(2 * lambda) s5(1) = s5(1) + (aux * E1) s5(2) = s5(2) + ((aux ^ 2) * lambda) Next i3 Call C_G2SWEEP(1, 1, m11, N, 2, 0.00000001, False) test(1) = (m11(1, 2) ^ 2) / (m11(2, 2) * m11(1, 1) / (N - 1)) Call C_G2SWEEP(1, 1, m21, N, 2, 0.00000001, False) test(2) = (m21(1, 2) ^ 2) / (m21(2, 2) * m21(1, 1) / (N - 1)) Call C_G2SWEEP(1, 1, m32, N, kk + 1, 0.00000001, Fa lse) For i1 = 1 To kk - 1 For j1 = 1 To kk - 1 For k1 = 1 To kk For l1 = 1 To kk m35(i1, j1) = m35(i1, j1) + (m33(i1 , k1) * m32(k1, l1) * m33(j1, l1)) Next l1 Next k1 Next j1 Next i1 For i1 = 1 To kk - 1 For j1 = 1 To kk - 1 m36(i1, j1) = m34(i1, j1) - m35(i1, j1) Next j1 Next i1 Call C_G2SWEEP(1, 0, m36, N, kk - 1 + 1, 0.00000001 , False) For i1 = 1 To kk - 1 For j1 = 1 To kk - 1 test(3) = test(3) + (M31(i1) * m36(i1, j1) * M31(j1)) Next j1 Next i1 test(4) = ((s4(1) - N * Application.Average(R_XY.Co lumns(NY))) ^ 2) / (2 * s4(2)) ReDim R(1 To 5, 1 To 7) R(1, 1) = "Hipótesis" R(1, 3) = "Test" R(1, 5) = "Valor c" & Chr(178) R(1, 6) = "gl" R(1, 7) = "Prob > c" & Chr(178) R(2, 1) = "Sobredispersión" R(2, 3) = "Regresión: f(constante)" R(3, 3) = "Regresión: f(lambda)" R(4, 3) = "Momentos condicionados" R(5, 3) = "Multiplicadores Lagrange" For i1 = 2 To 5 R(i1, 5) = test(i1 - 1) R(i1, 6) = IIf(i1 = 4, k - 1, 1) R(i1, 7) = Application.ChiDist(R(i1, 5), R(i1, 6)) R(i1, 7) = IIf(R(i1, 7) < 0.0001, "< 0,0001", R (i1, 7)) Next i1 avis = True If OPT(6) Then avis = False If UBound(MCOV, 1) <= 12 Then avis = False Call M6_ESCRIPTURA(5, "Contrastes de especificación ", avis) End Sub Private Sub M6_06(avis) '''''''''''''''''''''' 'Restriccions lineals' '''''''''''''''''''''' Dim aux(1 To 2) As Double, a1() As Double, a2() As Double, a3() As Double, a4() As Boolean, _ glr() As Integer, irest As Integer, i1 As Integ er, i2 As Integer, n_r() As String, w() As Double Call C_RESTRICCIONES_1(5, MCOV, a1, a2, a3, a4, w, glr, irest, n_r) If SORTIR Then SORTIR = False If irest <= 1 Then Exit Sub Else irest = irest - 1 End If

Page 173: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

172

'''''''''''''''''''''''''''''''''''''''''''''''''' 'Calcula l'amplada de columna per a la restricció' '''''''''''''''''''''''''''''''''''''''''''''''''' aux(1) = 0 For i1 = 1 To irest If Len(n_r(i1)) > aux(1) Then i2 = i1 aux(1) = Len(n_r(i1)) End If Next i1 With Cells(1, 11) aux(2) = .ColumnWidth With .Font .Bold = True .Name = "Arial" .Size = 7 End With .Value = n_r(i2) .Columns.AutoFit aux(1) = .ColumnWidth .Clear .ColumnWidth = aux(2) End With For i1 = 6 To 1 Step -1 If aux(1) > i1 * 9.57 Then Exit For Next i1 aux(2) = Application.max(i1 + 1, 1) ReDim R(1 To irest + 1, 1 To aux(2) + 3) R(1, 1) = "Restricción" R(1, aux(2) + 1) = "Valor c" & Chr(178) R(1, aux(2) + 2) = "gl" R(1, aux(2) + 3) = "Prob > c" & Chr(178) For i1 = 1 To irest R(i1 + 1, 1) = n_r(i1) R(i1 + 1, aux(2) + 1) = w(i1) R(i1 + 1, aux(2) + 2) = glr(i1) R(i1 + 1, aux(2) + 3) = Application.ChiDist(w(i 1), glr(i1)) R(i1 + 1, aux(2) + 3) = IIf(R(i1 + 1, aux(2) + 3) < 0.0001, "< 0,0001", R(i1 + 1, aux(2) + 3)) Next i1 If UBound(MCOV, 1) <= 12 Then avis = False Else avi s = True Call M6_ESCRIPTURA(6, "Restricciones lineales (Test de Wald)", avis) End Sub Private Sub M6_07(escala) ''''''''''''''''''''''''''' 'Escriptura de l'estimació' ''''''''''''''''''''''''''' Dim aux As Double, i1 As Integer ReDim R(1 To k + 2, 1 To 10) R(1, 1) = "Variable" R(1, 2) = "Parámetro" R(1, 3) = "Error" & Chr(10) & "Estándar" R(1, 4) = "Valor c" & Chr(178) R(1, 5) = "Prob > c" & Chr(178) R(1, 6) = "Intervalo Parámetro" & Chr(10) & "(sig.= " & Format(SIG, "0.00") & ")" R(1, 8) = "Valores ajustados por 'sobredispersión'" R(2, 8) = "Error Est." R(2, 9) = "Valor c" & Chr(178) R(2, 10) = "Prob > c" & Chr(178) If SIG = 0.01 Then aux = 2.575834515 ElseIf SIG = 0.05 Then aux = 1.959961082 ElseIf SIG = 0.1 Then aux = 1.644853 ElseIf SIG = 0.15 Then aux = 1.439530024 ElseIf SIG = 0.2 Then aux = 1.281550794 ElseIf SIG = 0.25 Then aux = 1.150349362 End If For i1 = 1 To k R(i1 + 2, 1) = "b" & i1 & "(" & LVAR(i1, 2) & " )" R(i1 + 2, 2) = B(i1) R(i1 + 2, 3) = Sqr(MCOV(i1, i1))

Page 174: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

173

R(i1 + 2, 4) = (R(i1 + 2, 2) / R(i1 + 2, 3)) ^ 2 R(i1 + 2, 5) = Application.ChiDist(R(i1 + 2, 4) , 1) R(i1 + 2, 5) = IIf(R(i1 + 2, 5) < 0.0001, "< 0, 0001", R(i1 + 2, 5)) R(i1 + 2, 6) = B(i1) - (aux * R(i1 + 2, 3)) R(i1 + 2, 7) = B(i1) + (aux * R(i1 + 2, 3)) R(i1 + 2, 8) = Sqr(MCOV(i1, i1) * escala) R(i1 + 2, 9) = (R(i1 + 2, 2) / R(i1 + 2, 8)) ^ 2 R(i1 + 2, 10) = Application.ChiDist(R(i1 + 2, 9 ), 1) R(i1 + 2, 10) = IIf(R(i1 + 2, 10) < 0.0001, "< 0,0001", R(i1 + 2, 10)) Next i1 Call M6_ESCRIPTURA(7, "Resultados de la estimación" , IIf(k > 36, True, False)) End Sub Private Sub M6_ESCRIPTURA_1(opcio As Integer) '''''''''''''''''''''''''''''''''''''''' 'AUXILIAR PER A L'ESCRIPTURA DE MATRIUS' '''''''''''''''''''''''''''''''''''''''' Dim avis As Boolean, dim1 As Integer, dim2 As Integ er, i1 As Integer, i2 As Integer, _ j1 As Integer, j2 As Integer, j22 As Integer, m axim2 As Integer, resta2 As Integer dim1 = UBound(MCOV, 1) - 1 dim2 = IIf(dim1 <= 9, dim1, 9) maxim2 = IIf(dim1 <= 9, 1, Int(dim1 / 9)) resta2 = IIf(dim1 <= 9, 0, dim1 - (maxim2 * 9)) If resta2 <> 0 Then maxim2 = maxim2 + 1 For j2 = 1 To maxim2 ReDim R(1 To dim1 + 1, 1 To IIf(j2 < maxim2, di m2, IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2 ))) + 1) For j22 = 1 To IIf(j2 < maxim2, dim2, IIf(j2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) i2 = j22 + ((j2 - 1) * 9) R(1, j22 + 1) = "b" & i2 & "(" & LVAR(i2, 2 ) & ")" Next j22 For i1 = 1 To dim1 R(i1 + 1, 1) = "b" & i1 & "(" & LVAR(i1, 2) & ")" For j22 = 1 To IIf(j2 < maxim2, dim2, IIf(j 2 = 1, dim2, IIf(resta2 <> 0, resta2, dim2))) R(i1 + 1, j22 + 1) = MCOV(i1, j22 + ((j 2 - 1) * 9)) Next j22 Next i1 If dim1 <= 9 Then avis = True ElseIf dim1 <= 18 Then avis = IIf(j2 = 2, True, False) ElseIf dim1 <= 27 Then avis = IIf(j2 = 1 Or j2 = 3, True, False) ElseIf dim1 <= 36 Then avis = IIf(j2 = 2, False, True) Else avis = True End If Call M6_ESCRIPTURA(8, "Matriz de varianzas y co varianzas" & IIf(j2 = 1, "", "(cont.)"), avis) Next j2 End Sub Private Sub M6_ESCRIPTURA(opcio As Integer, titol1 As String, avis) '''''''''''''''''''' 'Escriptura general' '''''''''''''''''''' Sheets(FULL_R).Activate ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' 'opcio=1 ==> Informació general de l'estimació ' 'opcio=2 ==> Criteris d'informació de l'ajustament ' 'opcio=3 ==> Mesures de bondat de l'ajustament ' 'opcio=4 ==> Test Raó de Versemblança, Multiplicado rs de Lagrange i Wald' 'opcio=5 ==> Contrastos d'especificació ' 'opcio=6 ==> Restriccions lineals ' 'opcio=7 ==> Estimació ' 'opcio=8 ==> Matriu de variàncies i covariàncies ' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''' Dim c(1 To 2) As Integer, i1 As Integer, j1 As Inte ger, k1 As Integer c(1) = UBound(R, 1) c(2) = UBound(R, 2) With Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 10) ) .ColumnWidth = 9.5 With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter

Page 175: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

174

.Interior.ColorIndex = 2 .RowHeight = 11 .VerticalAlignment = xlCenter End With With Cells(F - 1, 1) .Font.Bold = True .HorizontalAlignment = xlLeft .Value = titol1 End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) .Borders(xlEdgeTop).LineStyle = xlDouble .Borders(xlEdgeBottom).LineStyle = xlDouble .Interior.ColorIndex = 37 .Value = R End With With Range(Cells(F, 1), Cells(F + c(1) - 1, 1)) .Font.Bold = True .HorizontalAlignment = xlLeft End With If opcio <> 1 Then For j1 = 1 To c(2) i1 = IIf(opcio = 2 Or (opcio = 7 And j1 <= 7 ), 1, 0) With Range(Cells(F, j1), Cells(F + i1, j1)) If (opcio <> 7 Or (opcio = 7 And j1 <= 7)) Then .Borders(xlEdgeBottom).LineStyle = xlContinuo us .Font.Bold = True .MergeCells = True .WrapText = True End With Next j1 End If If opcio = 1 Then 'Informació general de l'estimac ió For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , 2)).MergeCells = True If c(2) = 4 Then Range(Cells(F + i1 - 1, 3), Cells(F + i1 - 1, 4)).MergeCells = True With Cells(F + i1 - 1, 3) .HorizontalAlignment = xlRight If i1 >= 4 + IIf(O <> 0, 1, 0) And i1 <= 5 + IIf(O <> 0, 1, 0) Then .NumberFormat = "###,0" If i1 = 6 + IIf(O <> 0, 1, 0) Then .Number Format = "0.00E+00" If i1 = 7 + IIf(O <> 0, 1, 0) Then If Abs(R(i1, 3)) >= 1000 And Abs(R(i1, 3)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, 3)) < 1000 And Abs(R(i1, 3 )) >= 10 ^ (-6) Then .NumberFormat = "##0.000000" End If End With Next i1 ElseIf opcio = 2 Then 'Criteris d'informació de l' ajustament Range(Cells(F, 2), Cells(F + c(1) - 1, 3)).Numbe rFormat = "###,0.000" ElseIf opcio = 3 Then 'Mesures de bondat de l'ajus tament Range(Cells(F, 2), Cells(F + c(1) - 1, 2)).Numbe rFormat = "###,0.0000" Range(Cells(F, 3), Cells(F + c(1) - 1, 3)).Numbe rFormat = "0" Range(Cells(F, 4), Cells(F + c(1) - 1, 4)).Numbe rFormat = "###,0.000" If c(1) > 3 Then Range(Cells(F + 2, 1), Cells(F + 2, c(2))).Borders(xlEdgeBottom).LineStyle = xlCon tinuous Cells(F + 2, 1).Characters(1, 1).Font.Name = "sy mbol" Cells(F + 2, 1).Characters(1, 1).Font.Bold = Tru e ElseIf opcio = 4 Or opcio = 6 Then 'Tests Pendents- Restriccions For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , c(2) - 3)).MergeCells = True Next i1 If opcio = 6 Then For i1 = 2 To c(1) With Cells(F + i1 - 1, 1) For j1 = 1 To Len(R(i1, 1)) If Mid(R(i1, 1), j1, 1) = "b" Then .Characters(j1, 1).Font.Name = " Symbol" .Characters(j1, 1).Font.Bold = T rue End If Next j1 End With Next i1 End If Cells(F, c(2) - 2).Characters(8, 1).Font.Name = "symbol" Cells(F, c(2) - 2).Characters(8, 1).Font.Bold = True Cells(F, c(2)).Characters(8, 1).Font.Name = "sym bol" Cells(F, c(2)).Characters(8, 1).Font.Bold = True For j1 = c(2) - 2 To c(2) With Range(Cells(F, j1), Cells(F + c(1), j1) ) If j1 = c(2) - 2 Then .NumberFormat = "### ,0.000" If j1 = c(2) - 1 Then .NumberFormat = "0" If j1 = c(2) Then .NumberFormat = "0.0000"

Page 176: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

175

End With Next j1 ElseIf opcio = 5 Then 'Contrastos d'especificació Cells(F, 5).Characters(8, 1).Font.Name = "symbol " Cells(F, 5).Characters(8, 1).Font.Bold = True Cells(F, 7).Characters(8, 1).Font.Name = "symbol " Cells(F, 7).Characters(8, 1).Font.Bold = True For i1 = 1 To c(1) Range(Cells(F + i1 - 1, 1), Cells(F + i1 - 1 , 2)).MergeCells = True With Range(Cells(F + i1 - 1, 3), Cells(F + i 1 - 1, 4)) .Font.Bold = True .HorizontalAlignment = xlLeft .MergeCells = True End With Next i1 For j1 = 5 To 7 With Range(Cells(F, j1), Cells(F + c(1) - 1, j1)) If j1 = 5 Then .NumberFormat = "###,0.000" If j1 = 6 Then .NumberFormat = "0" If j1 = 7 Then .NumberFormat = "0.0000" End With Next j1 ElseIf opcio = 7 Then 'Estimació Range(Cells(F, 6), Cells(F + 1, 7)).MergeCells = True Range(Cells(F, 8), Cells(F, 10)).MergeCells = Tr ue Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1) .Font.Name = "symbol" Range(Cells(F, 4), Cells(F, 5)).Characters(8, 1) .Font.Bold = True With Range(Cells(F + 1, 8), Cells(F + 1, 10)) .Borders(xlEdgeBottom).LineStyle = xlContinuou s .Font.Bold = True End With Range(Cells(F + 1, 9), Cells(F + 1, 10)).Charact ers(8, 1).Font.Name = "symbol" Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Name = "symbol" Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).C haracters(1, 1).Font.Bold = True Range(Cells(F + 2, 4), Cells(F + c(1) - 1, 4)).N umberFormat = "###,0.000" Range(Cells(F + 2, 5), Cells(F + c(1) - 1, 5)).N umberFormat = "0.0000" Range(Cells(F + 2, 9), Cells(F + c(1) - 1, 9)).N umberFormat = "###,0.000" Range(Cells(F + 2, 10), Cells(F + c(1) - 1, 10)) .NumberFormat = "0.0000" For i1 = 3 To c(1) For j1 = 2 To 8 If j1 = 2 Or j1 = 3 Or j1 = 6 Or j1 = 7 Or j1 = 8 Then With Cells(F + i1 - 1, j1) If Abs(R(i1, j1)) >= 1000 And Abs(R (i1, j1)) < 10 ^ 9 Then .NumberFormat = "###,0.000" If Abs(R(i1, j1)) < 1000 And Abs(R( i1, j1)) >= 10 ^ (-6) Then .NumberFormat = "##0.000 000" End With End If Next j1 Next i1 ElseIf opcio = 8 Then 'Matriu de variàncies i covar iàncies Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Borde rs(xlRight).LineStyle = xlContinuous For i1 = 2 To c(1) Cells(F + i1 - 1, 1).Characters(1, 1).Font.N ame = "symbol" Cells(F + i1 - 1, 1).Characters(1, 1).Font.B old = True Cells(F, i1).Characters(1, 1).Font.Name = "s ymbol" Cells(F, i1).Characters(1, 1).Font.Bold = Tr ue Next i1 End If If avis Then ActiveWindow.SelectedSheets.HPageBreak s.Add (Cells(F + c(1), 1)) F = F + c(1) + 2 Sheets(FULL).Activate End Sub

Page 177: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

176

Attribute VB_Name = "M7_Indices" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim AVISIMPOSTOS As Boolean, AVISRENDES As Boolean Private Sub Aceptar_Click() Dim i1 As Integer, i2 As Integer, i3 As Long, j1 As Integer, k1 As Integer, nr As Integer, rn As Integ er ERR_LEC = True For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then nr = i1 ERR_LEC = False Exit For End If Next i1 If ERR_LEC Then Me.Hide MsgBox "Debe seleccionar la variable RENTA.", vb Critical, TITOL Exit Sub End If ERR_LEC = True i2 = 0 For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then i2 = i2 + 1 ReDim Preserve VI(1 To i2) VI(i2) = i1 NI = i2 End If Next i1 For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 If NI > 8 Then ERR_LEC = True Me.Hide MsgBox "Sólo puede seleccionar un máximo de 8 va riables, de IMPUESTOS o TRANSFERENCIAS.", vbCritica l, TITOL Exit Sub End If If NI > 0 Then For i2 = 1 To NI If nr = VI(i2) Then ERR_LEC = True Me.Hide MsgBox LVAR(nr, 1) & " no puede ser RENTA e IMPUESTO o TRANSFERENCIA.", vbCritical, TITOL Exit Sub End If Next i2 End If If NPES <> 0 Then If NPES = nr Then ERR_LEC = True Me.Hide MsgBox LVAR(NPES, 1) & " no puede ser RENTA y FACTOR DE ELEVACIÓN.", vbCritical, TITOL Exit Sub End If End If If NI <> 0 Then For i1 = 1 To NI If NPES = VI(i1) Then ERR_LEC = True Me.Hide MsgBox LVAR(NPES, 1) & " no puede ser IMP UESTO o TRANSFERENCIA y FACTOR DE ELEVACIÓN.", vbCr itical, TITOL Exit Sub End If Next i1 End If If Application.Count(R_XY.Columns(nr)) <> N Or Appl ication.CountIf(R_XY.Columns(nr), "<0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(nr, 1) & " es negativo o no numérico.", vbCritical, TIT OL

Page 178: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

177

Exit Sub End If If NI <> 0 Then For i1 = 1 To NI If Application.Count(R_XY.Columns(VI(i1))) < > N Or Application.CountIf(R_XY.Columns(VI(i1)), "< 0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LV AR(VI(i1), 1) & " es negativo o no numérico.", vbCr itical, TITOL Exit Sub End If Next i1 End If If NPES <> 0 Then If Application.Count(R_XY.Columns(NPES)) <> N Or Application.CountIf(R_XY.Columns(NPES), "<=0") <> 0 Then ERR_LEC = True Me.Hide MsgBox "Algún valor de la variable " & LVAR(N PES, 1) & " es negativo, nulo o no numérico.", vbCr itical, TITOL Exit Sub End If End If ERR_LEC = False ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''' 'Filtres per als valors de l'aversió en Gini extes i Atkinson' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''' ATK = False 'quan ATK=false no es calcula atkins on GINIE = False 'quan GINIE=false no es calcula atki nson FGT = False 'quan FGT=false no es calcula fgt If gini2 Or atkinson Or pobfgt Then ReDim AVERSION(1 To 3, 1 To 3) If gini2 Then AVERSION(1, 1) = g1.Value AVERSION(2, 1) = g2.Value AVERSION(3, 1) = g3.Value If AVERSION(1, 1) = -1 And AVERSION(2, 1) = - 1 And AVERSION(3, 1) = -1 Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar al menos un parám etro de aversión " & _ "para calcular el índice de GINI ex tendido.", vbCritical, TITOL Exit Sub Else If (AVERSION(1, 1) = AVERSION(2, 1)) And A VERSION(1, 1) <> -1 Or _ (AVERSION(1, 1) = AVERSION(3, 1)) And A VERSION(1, 1) <> -1 Or _ (AVERSION(2, 1) = AVERSION(3, 1)) And A VERSION(2, 1) <> -1 Then ERR_LEC = True Me.Hide MsgBox "El parámetro de aversión del ín dice de GINI extendido " & _ "no puede estar repetido.", vbCr itical, TITOL Exit Sub End If End If If AVERSION(1, 1) <> -1 Or AVERSION(2, 1) <> -1 Or AVERSION(3, 1) <> -1 Then GINIE = True End If If atkinson Then AVERSION(1, 2) = at1.Value AVERSION(2, 2) = at2.Value AVERSION(3, 2) = at3.Value If AVERSION(1, 2) = -1 And AVERSION(2, 2) = - 1 And AVERSION(3, 2) = -1 Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar al menos un parám etro de aversión " & _ "para calcular el índice de ATKINSO N.", vbCritical, TITOL Exit Sub Else If (AVERSION(1, 2) = AVERSION(2, 2)) And A VERSION(1, 2) <> -1 Or _ (AVERSION(1, 2) = AVERSION(3, 2)) And A VERSION(1, 2) <> -1 Or _ (AVERSION(2, 2) = AVERSION(3, 2)) And A VERSION(2, 2) <> -1 Then ERR_LEC = True Me.Hide MsgBox "El parámetro de aversión del ín dice de ATKINSON " & _ "no puede estar repetido.", vbCr itical, TITOL Exit Sub End If End If If AVERSION(1, 2) <> -1 Or AVERSION(2, 2) <> -1 Or AVERSION(3, 2) <> -1 Then ATK = True End If If pobfgt Then

Page 179: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

178

AVERSION(1, 3) = fgt1.Value AVERSION(2, 3) = fgt2.Value AVERSION(3, 3) = fgt3.Value If AVERSION(1, 3) = -1 And AVERSION(2, 3) = - 1 And AVERSION(3, 3) = -1 Then ERR_LEC = True Me.Hide MsgBox "Debe seleccionar al menos un parám etro de aversión " & _ "para calcular el índice de FGT.", vbCritical, TITOL Exit Sub Else If (AVERSION(1, 3) = AVERSION(2, 3)) And A VERSION(1, 3) <> -1 Or _ (AVERSION(1, 3) = AVERSION(3, 3)) And A VERSION(1, 3) <> -1 Or _ (AVERSION(2, 3) = AVERSION(3, 3)) And A VERSION(2, 3) <> -1 Then ERR_LEC = True Me.Hide MsgBox "El parámetro de aversión del ín dice de FGT " & _ "no puede estar repetido.", vbCr itical, TITOL Exit Sub End If End If If AVERSION(1, 3) <> -1 Or AVERSION(2, 3) <> -1 Or AVERSION(3, 3) <> -1 Then FGT = True End If End If ''''''''''''''''''''''''''''''''''''''''''''''''''' 'Filtre pel valor de pobresa dels índexs de pobresa ''''''''''''''''''''''''''''''''''''''''''''''''''' If sen Then If Not IsNumeric(upobresa.Value) Or Val(upobresa .Value) <= 0 Then ERR_LEC = True Me.Hide MsgBox "El umbral de pobreza es incorrecto, d ebe ser un valor positivo.", vbCritical, TITOL Exit Sub End If End If '''''''''''''''''''''''''''''''''''''''''''' 'Filtre pel valor del nombre de replicacions '''''''''''''''''''''''''''''''''''''''''''' If var2 Or var3 Then If Not IsNumeric(replicaciones.Value) Or _ (Val(replicaciones.Value) < 10 Or Val(replica ciones.Value) > 1000) Then ERR_LEC = True Me.Hide MsgBox "El número de replicaciones es incorre cto, debe estar entre 10 y 1000.", vbCritical, TITO L Exit Sub End If End If ReDim XY(1 To N, 1 To 1 + NI + IIf(ef_red1 Or ef_re d2, NI, 0)), PES(1 To N) TN = 0 For i3 = 1 To N XY(i3, 1) = R_XY.Rows(i3).Columns(nr) Next i3 If NI > 0 Then For j1 = 1 To NI For i3 = 1 To N XY(i3, j1 + 1) = R_XY.Rows(i3).Columns(V I(j1)) Next i3 Next j1 If (ef_red1 Or ef_red2) Then k1 = 0 For i2 = 1 To NI k1 = k1 + 1 For i3 = 1 To N XY(i3, NI + 1 + k1) = XY(i3, 1) - XY( i3, i2 + 1) Next i3 Next i2 End If End If For i3 = 1 To N PES(i3) = 1 If NPES <> 0 Then PES(i3) = R_XY.Rows(i3).Colum ns(NPES) TN = TN + PES(i3) '==>Població elevada' Next i3 If IX = 1 Then LVAR(1, 2) = LVAR(nr, 1) Else LVAR(1 , 2) = "R" If NI > 0 Then For j1 = 1 To NI If IX = 1 Then LVAR(j1 + 1, 2) = LVAR(VI(j1) , 1) Else LVAR(j1 + 1, 2) = "I(" & Trim(Str(j1)) & ")" Next j1

Page 180: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

179

End If Call ANALISIS(1) End Sub Private Sub Cancelar_Click() SORTIR = True NPES = 0 Unload Me End Sub Private Sub ANALISIS(opcio As Integer) Dim i1 As Integer, j1 As Integer ''''''''''''''''''''''''''''''''' 'Determina les opcions de càlcul' ''''''''''''''''''''''''''''''''' ReDim II(1 To 6, 1 To 2), IR(1 To 17, 1 To 2) For i1 = 1 To 16 IR(i1, 1) = False Next i1 IR(1, 1) = True IR(1, 2) = "Gini" If gini2 Then For i1 = 1 To 3 If AVERSION(i1, 1) <> -1 Then IR(i1 + 1, 1) = True IR(i1 + 1, 2) = "Gini ext. (aversión=" & AVERSION(i1, 1) & ")" End If Next i1 End If If atkinson Then For i1 = 1 To 3 If AVERSION(i1, 2) <> -1 Then IR(i1 + 4, 1) = True IR(i1 + 4, 2) = "Atkinson (aversión=" & A VERSION(i1, 2) & ")" End If Next i1 End If IR(8, 1) = True IR(8, 2) = "Theil(0)" If theil1 Then IR(9, 1) = True IR(9, 2) = "Theil(1)" End If POBRESA = 0 If sen Or pobfgt Then POBRESA = Val(upobresa.Value) IR(10, 1) = True IR(11, 1) = True IR(12, 1) = True IR(13, 1) = True IR(10, 2) = "Umbral de pobreza" IR(11, 2) = "Proporción de pobres(H)" IR(12, 2) = "Brecha de pobreza(I)" IR(13, 2) = "Gini(entre pobres)" If sen Then IR(14, 1) = True IR(14, 2) = "Sen" End If If pobfgt Then For i1 = 1 To 3 If AVERSION(i1, 3) <> -1 Then IR(i1 + 14, 1) = True IR(i1 + 14, 2) = "FGT (aversión=" & AV ERSION(i1, 3) & ")" End If Next i1 End If End If For i1 = 1 To 6 II(i1, 1) = False Next i1 If NI > 0 Then II(1, 1) = True II(1, 2) = "Concentración" II(2, 1) = True II(2, 2) = "Concentración relativa" II(3, 1) = True

Page 181: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

180

II(3, 2) = "Kakwani" II(4, 1) = True II(4, 2) = "Suits" If ef_red1 Then II(5, 1) = True II(5, 2) = "Reynolds-Smolensky" End If If ef_red2 Then II(6, 1) = True II(6, 2) = "Reynolds-Smolensky modificado" End If End If If N > 15000 Then IVAR(1) = False IVAR(2) = False IVAR(3) = False REP_BOOT = 0 Else IVAR(1) = var1.Value IVAR(2) = var2.Value IVAR(3) = var3.Value If IVAR(1) Then REP_BOOT = 0 Else REP_BOOT = Val (replicaciones.Value) SIG = n_sig.Value End If GR(1) = lorenz.Value GR(2) = concen.Value If GR(2) And Not GR(1) Then GR(1) = True GR(3) = tipos.Value Me.Hide End Sub Private Sub IMPOSTOS(opcio As Integer) Dim i1 As Integer AVISIMPOSTOS = False For i1 = 1 To R_XY.Columns.Count If xs.Selected(i1 - 1) Then AVISIMPOSTOS = True Exit For End If Next i1 If AVISIMPOSTOS Then Frame2.Enabled = True For Each CTL In Frame2.Controls CTL.Enabled = True Next CTL concen.Enabled = True tipos.Enabled = True Else Frame2.Enabled = False For Each CTL In Frame2.Controls CTL.Enabled = False Next CTL ef_red1.Value = False ef_red2.Value = False concen.Enabled = False concen.Value = False tipos.Enabled = False tipos.Value = False End If End Sub Private Sub RENDES(opcio As Integer) Dim i1 As Integer AVISRENDES = False For i1 = 1 To R_XY.Columns.Count If ys.Selected(i1 - 1) Then AVISRENDES = True Exit For End If Next i1

Page 182: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

181

If AVISRENDES Then Frame1.Enabled = True For Each CTL In Frame1.Controls CTL.Enabled = True Next CTL If N <= 15000 Then Frame3.Enabled = True For Each CTL In Frame3.Controls CTL.Enabled = True Next CTL var1.Value = True End If Frame4.Enabled = True lorenz.Enabled = True End If End Sub Private Sub gini2_Click() Dim i1 As Integer, j1 As Integer If gini2 Then If Not atkinson Then Label11.Visible = True Label11.Top = 7 Framegini2.Visible = True For Each CTL In Framegini2.Controls CTL.Visible = True Next CTL Else Framegini2.Visible = False If Not atkinson Then Label11.Visible = False If atkinson Then Label11.Top = 20 For Each CTL In Framegini2.Controls CTL.Visible = False Next CTL End If End Sub Private Sub atkinson_Click() Dim i1 As Integer, j1 As Integer If atkinson Then If Not gini2 Then Label11.Visible = True Label11.Top = 20 End If Frameatkinson.Visible = True For Each CTL In Frameatkinson.Controls CTL.Visible = True Next CTL Else Frameatkinson.Visible = False If Not gini2 Then Label11.Visible = False For Each CTL In Frameatkinson.Controls CTL.Visible = False Next CTL End If End Sub Private Sub sen_Click() If sen Then Label131.Visible = True upobresa.Visible = True Else Label131.Visible = False upobresa.Visible = False upobresa.Value = 0 End If End Sub Private Sub pobfgt_Click() Dim i1 As Integer, j1 As Integer If pobfgt Then sen.Value = True sen.Locked = True Label132.Visible = True

Page 183: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

182

Framefgt.Visible = True For Each CTL In Framefgt.Controls CTL.Visible = True Next CTL Else sen.Locked = False Label132.Visible = False For Each CTL In Framefgt.Controls CTL.Visible = False Next CTL End If End Sub Private Sub var1_Click() If var1 Then Frame31.Visible = False Label32.Visible = False replicaciones.Visible = False End If End Sub Private Sub var2_Click() If var2 Then Frame31.Visible = True Label32.Visible = True replicaciones.Visible = True End If End Sub Private Sub var3_Click() If var3 Then Frame31.Visible = True Label32.Visible = True replicaciones.Visible = True End If End Sub Private Sub ps_Click() Dim i1 As Integer For i1 = 1 To R_XY.Columns.Count If ps.Selected(i1 - 1) Then NPES = i1 Exit For End If Next i1 End Sub Private Sub UserForm_Layout() n_sig.Move Height:=12, Top:=5, Width:=40 End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then SORTIR = True Unload Me End Sub Private Sub ys_Click() Label2.Enabled = True Label3.Enabled = True xs.Enabled = True ps.Enabled = True End Sub Private Sub ys_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call RENDES(1) End Sub Private Sub xs_MouseMove(ByVal Button As Integer, B yVal Shift As Integer, ByVal X As Single, ByVal Y A s Single) Call IMPOSTOS(1) End Sub

Page 184: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

183

Attribute VB_Name = "M7" Option Explicit Public ATK As Boolean, AVERSION() As Double, FGT As Boolean, GINIE As Boolean, GR(1 To 3) As Boolean, II(), _ INDEXS() As Double, IR(), IVAR(1 To 3) As Bo olean, NI As Integer, POBRESA As Double, REP_BOOT A s Double, _ TN As Double, VI() As Integer, VR() As Integ er Sub M7_(opcio As Integer) '''''''' 'INDEXS' '''''''' ''''''''''''''''''''''''''''''''''''''''''''' 'Identificació de les opcions ' ''''''''''''''''''''''''''''''''''''''''''''' 'sempre descriptiu (M7_01) ' 'sempre decils (M7_02) ' 'sempre índexs (M7_03) ' 'RG(1), RG(2), RG(3) gràfics (M7_GRAFICS)' ''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' 'Carrega el quadre de diàleg MicroEconometria1: Mod elos de Regresión' ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''' Dim h As Single, i1 As Integer ReDim v(R_XY.Columns.Count - 1) As String, vatkinso n(50) As Double, vfgt(50) As Double, vgini(40) As D ouble, vsig(5) As Double For i1 = 0 To R_XY.Columns.Count - 1 v(i1) = LVAR(i1 + 1, 1) Next i1 vatkinson(50) = -1 vfgt(50) = -1 vgini(40) = -1 For i1 = 50 To 0 Step -1 If i1 > 0 Then vatkinson(50 - i1) = 0.1 * i1 If i1 > 0 Then vfgt(50 - i1) = 0.1 * i1 If i1 > 10 Then vgini(50 - i1) = 0.1 * i1 Next i1 For i1 = 5 To 0 Step -1 If i1 > 0 Then vsig(5 - i1) = 0.05 * i1 Else vs ig(5 - i1) = 0.01 Next i1 TITOL = "MicroEconometría: Índices" h = Application.min(110, 11 * R_XY.Columns.Count) With M7_Indices .ys.Move Height:=h, Top:=15, Width:=90 .ys.List = v .xs.Move Height:=h, Top:=15, Width:=90 .xs.List = v .ps.Move Height:=h, Top:=15, Width:=90 .ps.List = v .g1.List = vgini .g1.Selected(35) = True .g2.List = vgini .g2.Selected(40) = True .g3.List = vgini .g3.Selected(40) = True .at1.List = vatkinson .at1.Selected(45) = True .at2.List = vatkinson .at2.Selected(50) = True .at3.List = vatkinson .at3.Selected(50) = True .fgt1.List = vfgt .fgt1.Selected(40) = True .fgt2.List = vfgt .fgt2.Selected(50) = True .fgt3.List = vfgt .fgt3.Selected(50) = True .n_sig.List = vsig .n_sig.Selected(4) = True End With ERR_LEC = True SORTIR = False Do While ERR_LEC = True M7_Indices.Show If SORTIR Then ERR_LEC = False

Page 185: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

184

Loop Unload M7_Indices If SORTIR Then Exit Sub ReDim ds(1 To 2 * (NI + 1), 12) As Double, s(1 To N I + 1) As Double, ts(NI, 12) As Double Call C_ORDENA(5, 1, 1 + NI + IIf(II(5, 1) Or II(6, 1), NI, 0)) Call M7_01(s) Call M7_02(ds, s, ts) Call M7_03(1) If GR(1) Or GR(2) Or GR(3) Then Call M7_GRAFICS(ds, ts) INOU = INOU + 1 End Sub Private Sub M7_01(s) ''''''''''''''''''''''''''''''''' 'INDEXS: ESTADÍSTICA DESCRIPTIVA' ''''''''''''''''''''''''''''''''' Dim i1 As Long, i2 As Long, a As Integer, i As Inte ger, j As Integer, k As Integer, titol1 As String ReDim aux(1 To NI + 1, 1 To 5) As Double, R(1 To NI + 4, 1 To 9) ''''''''''''''''''''''''''''''''''''''' 'MITJANES I SUMES DE RENDES I IMPOSTOS' ''''''''''''''''''''''''''''''''''''''' For i1 = 1 To N For j = 1 To NI + 1 aux(j, 1) = aux(j, 1) + (XY(i1, j) * PES(i1 )) aux(j, 2) = aux(j, 2) + (XY(i1, j) * (PES(i 1) ^ 2)) aux(j, 3) = aux(j, 3) + ((XY(i1, j) ^ 2) * (PES(i1) ^ 2)) aux(j, 4) = aux(j, 4) + ((XY(i1, j) ^ 2) * PES(i1)) Next j aux(1, 5) = aux(1, 5) + (PES(i1) ^ 2) Next i1 s(1) = aux(1, 1) If NI > 0 Then For i = 1 To NI s(i + 1) = aux(i + 1, 1) Next i End If R(3, 1) = "Variable" R(1, 2) = "Media (unidades originales)" R(3, 2) = "Valor" R(3, 3) = "Err. Est." R(2, 4) = "Límites 95%" R(3, 4) = "Inferior" R(3, 5) = "Superior" R(1, 6) = "Suma (unidades originales / 1.000.000)" R(3, 6) = "Valor" R(3, 7) = "Err. Est." R(2, 8) = "Límites 95%" R(3, 8) = "Inferior" R(3, 9) = "Superior" For j = 1 To NI + 1 R(j + 3, 1) = LVAR(j, 2) R(j + 3, 2) = aux(j, 1) / TN R(j + 3, 3) = Sqr(aux(j, 3) - (2 * aux(j, 1) * aux(j, 2) / TN) + (((aux(j, 1) / TN) ^ 2) * aux(1, 5))) / TN R(j + 3, 4) = R(j + 3, 2) - (1.96 * R(j + 3, 3) ) R(j + 3, 5) = R(j + 3, 2) + (1.96 * R(j + 3, 3) ) R(j + 3, 6) = aux(j, 1) / 1000000 R(j + 3, 7) = Sqr(aux(j, 3) - ((aux(j, 1) ^ 2) / N)) / 1000000 R(j + 3, 8) = R(j + 3, 6) - (1.96 * R(j + 3, 7) ) R(j + 3, 9) = R(j + 3, 6) + (1.96 * R(j + 3, 7) ) Next j titol1 = "RESULTADOS DESCRIPTIVOS (Tamaño muestral = " & Format(N, "##,##0") & ") " titol1 = titol1 & IIf(NPES <> 0, "(Población = " & Format(Round(TN), "##,##0") & ") (Cálculos elevados )", "") Call M7_ESCRIPTURA(1, titol1) '''''''''''''''''''' 'INDEXS: PERCENTILS' '''''''''''''''''''' If N >= 500 Then ReDim R(1 To NI + 3, 1 To 12), xx(1 To N) As Dou ble R(2, 1) = "Variable" R(1, 2) = "Mínimo"

Page 186: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

185

R(2, 2) = 0 R(2, 3) = 0.01 R(2, 4) = 0.05 R(2, 5) = 0.1 R(1, 6) = "Q1" R(2, 6) = 0.25 R(1, 7) = "MEDIANA" R(2, 7) = 0.5 R(1, 8) = "Q3" R(2, 8) = 0.75 R(2, 9) = 0.9 R(2, 10) = 0.95 R(2, 11) = 0.99 R(1, 12) = "Máximo" R(2, 12) = 1 For j = 1 To NI + 1 R(j + 2, 1) = LVAR(j, 2) aux(1, 1) = 0 For i1 = 1 To N aux(1, 1) = aux(1, 1) + PES(IND(i1, j)) xx(i1) = aux(1, 1) / TN Next i1 i2 = 1 For k = 2 To 10 For i1 = i2 To N If xx(i1) >= R(2, k + 1) Then R(j + 2, k + 1) = XY(IND(i1, j), j) i2 = i1 Exit For End If Next i1 Next k R(j + 2, 2) = XY(IND(1, j), j) R(j + 2, 12) = XY(IND(N, j), j) Next j Call M7_ESCRIPTURA(11, "PERCENTILES" & IIf(NPES <> 0, "(Cálculos elevados)", "")) End If ''''''''''''''''''''''''''''''' 'INDEXS: TIPUS EFECTIUS TOTALS' ''''''''''''''''''''''''''''''' If NI > 0 Then ReDim R(1 To NI + 1, 1 To 2) R(1, 1) = "Variable" R(1, 2) = LVAR(1, 2) For i = 1 To NI R(i + 1, 1) = LVAR(i + 1, 2) R(i + 1, 2) = s(i + 1) / s(1) Next i Call M7_ESCRIPTURA(12, "TIPOS EFECTIVOS TOTALES" & IIf(NPES <> 0, "(Cálculos elevados)", "")) End If End Sub Private Sub M7_02(ds, s, ts) '''''''''''''''' 'INDEXS: DECILS' '''''''''''''''' Dim a As Integer, i As Integer, j As Integer, k As Integer, l2 As Integer, titol1 As String titol1 = IIf(NPES <> 0, "(Cálculos elevados)", "") '''''''''''''''''''''''''''''' 'Defineix p(1,1 to 12)=decils' '''''''''''''''''''''''''''''' ReDim p(1 To 12, 1 To 2) As Double For j = 1 To 12 p(j, 1) = IIf(j < 10, j / 10, IIf(j = 10, 0.95, IIf(j = 11, 0.98, 1))) Next j Call M7_02_1(p, ds, s) ''''''''''''''''''''' 'Escriptura "DECILS"' ''''''''''''''''''''' ReDim R(1 To 2 * (NI + 1) + 2, 1 To 13) R(2, 1) = "Variable" R(3, 1) = LVAR(1, 2) If NI > 0 Then

Page 187: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

186

For i = 1 To NI R((2 * i) + 3, 1) = LVAR(i + 1, 2) Next i End If For j = 1 To 12 R(1, j + 1) = p(j, 1) R(2, j + 1) = "acum." For k = 1 To NI + NI + 2 R(k + 2, j + 1) = ds(k, j) Next k Next j Call M7_ESCRIPTURA(2, "DECILAS (ordenación según " & LVAR(1, 2) & ") " & titol1) ''''''''''''''''''''''' 'Càlcul tipus efectius' ''''''''''''''''''''''' If NI > 0 Then ''''''''''''''''''''' 't(1 to NI, 1 to 12)' ''''''''''''''''''''' For j = 1 To 12 For i = 1 To NI k = (2 * i) + 1 If ds(1, j) <> 0 Then ts(i, j) = (ds(k, j) * s(i + 1)) / (ds(1, j) * s(1)) Next i Next j ''''''''''''''''''''''''''''' 'Escriptura "Tipus efectius"' ''''''''''''''''''''''''''''' ReDim R(1 To NI + 1, 1 To 13) For i = 1 To NI R(i + 1, 1) = LVAR(i + 1, 2) Next i R(1, 1) = "Variable" For j = 1 To 12 R(1, j + 1) = p(j, 1) For i = 1 To NI R(i + 1, j + 1) = ts(i, j) Next i Next j Call M7_ESCRIPTURA(3, "TIPOS EFECTIVOS s/" & LVA R(1, 2) & " (ordenación según " & LVAR(1, 2) & ") " & titol1) End If End Sub Private Sub M7_02_1(p, ds, s) ''''''''''''''''''''''''' 'INDEXS: AUXILIAR DECILS' ''''''''''''''''''''''''' Dim aux As Double, i1 As Long, i2 As Long, j As Int eger, k As Integer ReDim xx(1 To N, 1 To NI + 2) As Double For j = 1 To NI + 1 If s(j) <> 0 Then aux = 0 For i1 = 1 To N aux = aux + (XY(IND(i1, 1), j) * PES(IND (i1, 1))) xx(i1, j) = aux / s(j) Next i1 End If Next j aux = 0 For i1 = 1 To N aux = aux + PES(IND(i1, 1)) xx(i1, NI + 2) = aux / TN Next i1 ''''''''''''''''''''''''''''''''''''''''''''''''''' ' 'p(1 to 12, 2) = Observació on comença cada decil ' ''''''''''''''''''''''''''''''''''''''''''''''''''' ' i2 = 1 For j = 1 To 11 For i1 = i2 To N

Page 188: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

187

If xx(i1, NI + 2) >= p(j, 1) Then p(j, 2) = i1 i2 = i1 Exit For End If Next i1 Next j p(12, 2) = N ''''''''''''''''''''''''''''''''''''' 'Càlcul DECILS ' ''''''''''''''''''''''''''''''''''''' '1a. dimensió senar ==> no acumulat' '1a. dimensió parell ==> acumulat ' ''''''''''''''''''''''''''''''''''''' For j = 1 To NI + 1 For k = 1 To 12 i1 = p(k, 2) ds(2 * j, k) = xx(i1, j) ds((2 * j) - 1, k) = ds((2 * j), k) - ds(2 * j, k - 1) Next k Next j End Sub Private Sub M7_03(opcio As Integer) ''''''''''''''''' 'INDEXS: CÀLCULS' ''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''' 'IVAR(1)=True ==> Métode err. est. asimptòtic 'IVAR(2)=True ==> Métode err. est. boostrap 'IVAR(3)=True ==> Métode boostrap-t (percentils t-s tudent) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''' Dim avis As Boolean, c As Integer, dimR As Integer, i As Integer, i1 As Long, i2 As Long, j As Integer , j1 As Integer, _ k As Integer, k1 As Integer, l As Integer, tito l0 As String, titol1 As String ReDim INDEXS(1 To (6 * NI) + 17, 1 To 7), boots(1 T o N) As Double, _ i_b(1 To (6 * NI) + 17, 0 To REP_BOOT) As Dou ble, vindexs(1 To (6 * NI) + 17, 0 To REP_BOOT) As Double '''''''''''''''''''''''''''''''''''''''''' 'Gini =indexs( 1 ,1) 'Gini extes =indexs( 2:4 ,1) 'Atkinson =indexs( 5:7 ,1) 'Theil(0) =indexs( 8:8 ,1) 'Theil(1) =indexs( 9:9 ,1) 'Umbral de pobreza =indexs( 10:10,1 '% de pobres (H) =indexs( 11:11,1) 'Brecha pobreza(I) =indexs( 12:12,1) 'Gini (pobres) =indexs( 13:13,1) 'Sen rendes =indexs( 14:14,1) 'Foster et alt. =indexs( 15:17,1) '''''''''''''''''''''''''''''''''''''''''' 'Concentració =indexs(6(i-1)+18 ,1) 'Concentració rel. =indexs(6(i-1)+19 ,1) 'Kakwani =indexs(6(i-1)+20 ,1) 'Suits =indexs(6(i-1)+21 ,1) 'Reynolds-Smolensky=indexs(6(i-1)+22 ,1) 'Reynolds-Smolensky=indexs(6(i-1)+23 ,1) '''''''''''''''''''''''''''''''''''''''''' Rnd (-1) Randomize 123456 Dim aux As Double, aux1 As Double, iaux As Long, n0 As Long, n_p As Long, _ pes1 As Double, pes2 As Double, sr0 As Double, tn0 As Double, tn_p As Double Dim cr As Double, ddr_ As Double, d1r_ As Double, d 1r_p As Double, mddr As Double, mr As Double, _ mr_p As Double, md1r As Double, s1d1r As Double , s1g_p As Double, s1s_p As Double, _ s2d1r As Double, s2g_p As Double, s2s_p As Doub le, theta As Double, theta1 As Double, theta2 As Do uble, _ theta3 As Double, vd1r As Double, s1d1z As Doub le, s2d1z As Double, vd1z As Double For c = 0 To REP_BOOT ReDim d1r(1 To N) As Double, ddr(1 To N) As Dou ble, d1ar(1 To N) As Double aux1 = 0: cr = 0: ddr_ = 0: d1r_ = 0: mdd r = 0: md1r = 0: mr = 0: s1d1r = 0: s1d1z = 0: s1g_p = 0: s1s_p = 0: s2d 1r = 0: s2d1z = 0: s2g_p = 0: s2s_p = 0: vd1r = 0: vd1z = 0

Page 189: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

188

If NI > 0 Then ReDim mi(1 To NI) As Double, ci(1 To NI) As Double, d1i_(1 To NI) As Double, md1i(1 To NI) As D ouble, _ ddi_(1 To NI) As Double, mddi(1 To NI) As Double, d1ai(1 To NI) As Double, s1d1i(1 To NI) As Double, _ s2d1i(1 To NI) As Double, s3d1i(1 To N I) As Double, vd1i(1 To NI) As Double, vcd1i(1 To N I) As Double, _ vdd(1 To NI, 1 To 2) As Double, ddia(1 To NI, 1 To 2) As Double, s1dd(1 To NI, 1 To 2) As Double, _ s2dd(1 To NI, 1 To 2) As Double, _ d1i(1 To N, 1 To NI) As Double, ddi(1 To N, 1 To NI) As Double If II(5, 1) Or II(6, 1) Then ReDim mk(1 To NI) As Double, ck(1 To NI) As Double, ddk_(1 To NI) As Double, mddk(1 To NI) A s Double, _ d1k_(1 To NI, 1 To 2) As Double, md 1k(1 To NI, 1 To 2) As Double, d1ak(1 To NI) As Dou ble, _ s1d1k(1 To NI) As Double, s2d1k(1 T o NI) As Double, s3d1k(1 To NI) As Double, _ vd1k(1 To NI) As Double, vcd1k(1 To NI) As Double, _ d1k(1 To N, 1 To NI, 1 To 2) As Dou ble, ddk(1 To N, 1 To NI) As Double End If End If For i1 = 1 To N If c = 0 Then boots(i1) = i1 If c > 0 Then boots(i1) = Int((N * Rnd) + 1 ) Y(i1) = XY(boots(i1), 1) IND(i1, 1) = boots(i1) Next i1 Call C_ORDENA_1(1, N, 1) ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''' 'If c = 0 Then ' Open "C:\PROYECTOS\IndicesJordi\Program\Bootstr ap_t_mostres.txt" For Output As #100 ' Write #100, "c", "pes", "x1", "x2", "x3" 'End If 'For i1 = 1 To N ' Write #100, c, PES(IND(i1,1)), XY(IND(i1,1), 1 ), XY(IND(i1, 1), 2), XY(IND(i1, 1), 3) 'Next i1 'If c = RBOOT Then Close #100 ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''' TN = 0 n_p = 0 For i1 = 1 To N iaux = IND(i1, 1) TN = TN + PES(iaux) mr = mr + (XY(iaux, 1) * PES(iaux)) If POBRESA <> 0 Then If XY(iaux, 1) <= POBRESA Then n_p = n_p + 1 'pobre s tn_p = TN 'pesos pobres mr_p = mr End If End If Next i1 mr = mr / TN 'mitja na If POBRESA <> 0 Then mr_p = mr_p / tn_p 'mitja na pobres If NI > 0 Then For i = 1 To NI For i1 = 1 To N iaux = IND(i1, 1) mi(i) = mi(i) + (XY(iaux, i + 1) * P ES(iaux)) Next i1 mi(i) = mi(i) / TN Next i End If ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''' 'Índexs de desigualtat, entropia i pobresa: gin i, gini extès, atkinson, theil, sen, fgt ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''' pes1 = 0 pes2 = 0 For i1 = 1 To N iaux = IND(i1, 1) pes1 = pes1 + PES(iaux) pes2 = pes1 / TN If pes2 > 1 Then pes2 = 1 cr = cr * (1 - PES(iaux) / pes1) + (XY(iaux , 1) * PES(iaux) / pes1)

Page 190: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

189

d1r(iaux) = 2 * pes1 * (XY(iaux, 1) - cr) d1r_ = d1r_ + (d1r(iaux) * PES(iaux)) If POBRESA <> 0 Then If XY(iaux, 1) <= POBRESA Then d1r_p = d 1r_ End If ddr(iaux) = pes2 * (cr - XY(iaux, 1)) + XY( iaux, 1) ddr_ = ddr_ + (ddr(iaux) * PES(iaux)) Next i1 md1r = d1r_ / (TN ^ 2) mddr = ddr_ / TN i_b(1, c) = md1r / (2 * mr) 'Gini If IVAR(1) Or IVAR(3) Then For i1 = 1 To N iaux = IND(i1, 1) d1ar(iaux) = (i_b(1, c) * XY(iaux, 1)) - ((d1r(iaux) / TN) - XY(iaux, 1)) s1d1r = s1d1r + (d1ar(iaux) * PES(iaux)) s2d1r = s2d1r + ((d1ar(iaux) ^ 2) * PES( iaux)) Next i1 vd1r = ((s2d1r - ((s1d1r ^ 2) / TN)) / (TN - 1)) / (N * (mr ^ 2)) vindexs(1, c) = vd1r 'var. Gini End If If Not GINIE Then GoTo NO_GINIE For j1 = 1 To 3 If Not IR(j1 + 1, 1) Then GoTo NO_GINIE1 ReDim m(1 To 2) theta = AVERSION(j1, 1) - 1 pes1 = 0 pes2 = 0 For i1 = 1 To N iaux = IND(i1, 1) pes1 = pes1 + PES(iaux) pes2 = pes1 / TN If pes2 > 1 Then pes2 = 1 m(1) = m(1) + (PES(iaux) * ((1 - pes2) ^ theta)) Next i1 pes1 = 0 pes2 = 0 For i1 = 1 To N iaux = IND(i1, 1) pes1 = pes1 + PES(iaux) pes2 = pes1 / TN If pes2 > 1 Then pes2 = 1 m(2) = m(2) + ((XY(iaux, 1) - mr) * ((( 1 - pes2) ^ theta) - m(1)) * PES(iaux)) Next i1 i_b(j1 + 1, c) = -(m(2) / TN) * (AVERSION(j 1, 1) / mr) 'Gini extès NO_GINIE1: Next j1 NO_GINIE: If Not ATK Then GoTo NO_ATK For j1 = 1 To 3 ReDim m(1 To 3) If Not IR(j1 + 4, 1) Or AVERSION(j1, 2) = 1 Then GoTo NO_ATK1 theta1 = 1 - AVERSION(j1, 2) theta2 = theta1 * 2 theta3 = theta1 + 1 n0 = 0 sr0 = 0 tn0 = 0 For i1 = 1 To N iaux = IND(i1, 1) If XY(iaux, 1) > 0 Then sr0 = sr0 + (XY(iaux, 1) * PES(iaux) ) n0 = n0 + 1 tn0 = tn0 + PES(iaux) m(1) = m(1) + ((XY(iaux, 1) ^ theta1 ) * PES(iaux)) m(2) = m(2) + ((XY(iaux, 1) ^ theta2 ) * PES(iaux)) m(3) = m(3) + ((XY(iaux, 1) ^ theta3 ) * PES(iaux)) End If Next i1 m(1) = m(1) / tn0 m(2) = m(2) / tn0 m(3) = m(3) / tn0 i_b(j1 + 4, c) = (1 - (m(1) ^ (1 / theta1)) / (sr0 / tn0)) 'Atkinson(aversio<>1) NO_ATK1: Next j1 NO_ATK:

Page 191: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

190

k = 0 If ATK Then If AVERSION(1, 2) = 1 Then k = 1 If AVERSION(2, 2) = 1 Then k = 2 If AVERSION(3, 2) = 1 Then k = 3 End If ReDim m(1 To 7) n0 = 0 tn0 = 0 For i1 = 1 To N iaux = IND(i1, 1) If XY(iaux, 1) > 0 Then n0 = n0 + 1 tn0 = tn0 + PES(iaux) m(1) = m(1) + (XY(iaux, 1) * PES(iaux)) m(2) = m(2) + (Log(XY(iaux, 1)) * PES(ia ux)) m(3) = m(3) + (XY(iaux, 1) * Log(XY(iaux , 1)) * PES(iaux)) If IVAR(1) Or IVAR(3) Then m(4) = m(4) + ((XY(iaux, 1) ^ 2) * PE S(iaux)) m(5) = m(5) + ((Log(XY(iaux, 1)) ^ 2) * PES(iaux)) m(6) = m(6) + (((XY(iaux, 1) * Log(XY (iaux, 1))) ^ 2) * PES(iaux)) m(7) = m(7) + ((XY(iaux, 1) ^ 2) * Lo g(XY(iaux, 1)) * PES(iaux)) End If End If Next i1 For j1 = 1 To 7 m(j1) = m(j1) / tn0 Next j1 If ATK And k <> 0 Then i_b(4 + k, c) = (1 - (Ex p(m(2)) / m(1))) 'Atkin son(1) i_b(8, c) = (Log(m(1)) - m(2)) 'Theil (0) If IR(9, 1) Then i_b(9, c) = ((m(3) / m(1)) - L og(m(1))) 'Theil (1) If IVAR(1) Or IVAR(3) Then m(4) = m(4) - (m(1) ^ 2) aux = m(4) / (m(1) ^ 2) aux = aux + (m(5) - (m(2) ^ 2)) aux = aux - (2 * (m(3) - (m(1) * m(2))) / m( 1)) If ATK And k <> 0 Then vindexs(4 + k, c) = ( (Exp(2 * m(2)) / (m(1) ^ 2)) * aux) / n0 'var Atkinson(1) vindexs(8, c) = aux / n0 'var T heil(0) If IR(9, 1) Then aux = m(4) * ((m(3) + m(1)) ^ 2) / (m(1) ^ 2) aux = aux + (m(6) - (m(3) ^ 2)) aux = aux - (2 * (m(3) + m(1)) * (m(7) - (m(1) * m(3))) / m(1)) vindexs(9, c) = (aux / (m(1) ^ 2)) / n0 'var T heil(1) End If End If If POBRESA = 0 Then GoTo NO_POBRESA i_b(10, c) = POBRESA 'Pobre sa i_b(11, c) = tn_p / TN 'H i_b(12, c) = 1 - mr_p / POBRESA 'I i_b(13, c) = d1r_p / ((tn_p ^ 2) * (2 * mr_p)) 'Gini( pobres) i_b(14, c) = i_b(11, c) * (i_b(12, c) + (1 - i_ b(12, c)) * i_b(13, c) * (n_p / (n_p + 1))) 'Sen If IVAR(1) Or IVAR(3) Then For i1 = 1 To N iaux = IND(i1, 1) If XY(iaux, 1) <= POBRESA Then aux = (i_b(13, c) * XY(iaux, 1)) - (( d1r(iaux) / tn_p) - XY(iaux, 1)) s1g_p = s1g_p + (aux * PES(iaux)) s2g_p = s2g_p + ((aux ^ 2) * PES(iaux )) aux = (d1r(iaux) / TN) + (i_b(11, c) * (XY(iaux, 1) - mr_p)) 'phi (ull TN o tn_p) aux1 = (POBRESA - (d1r_p / (2 * tn_p ^ 2))) - XY(iaux, 1) + (aux / i_b(11, c)) s1s_p = s1s_p + (aux1 * PES(iaux)) s2s_p = s2s_p + ((aux1 ^ 2) * PES(iau x)) End If Next i1 vindexs(13, c) = ((s2g_p - ((s1g_p ^ 2) / tn _p)) / (tn_p - 1)) / (n_p * (mr_p ^ 2)) 'var. Gp vindexs(14, c) = ((s2s_p - ((s1s_p ^ 2) / TN )) / (TN - 1)) / (N * POBRESA ^ 2) 'var. Sen (ull TN o tn_p) End If If Not FGT Then GoTo NO_FGT For j1 = 1 To 3 If Not IR(j1 + 14, 1) Then GoTo NO_FGT1 aux = 0 For i1 = 1 To N iaux = IND(i1, 1)

Page 192: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

191

If XY(iaux, 1) <= POBRESA Then aux = aux + ((POBRESA - XY(iaux, 1)) ^ AVERSION(j1, 3) * PES(iaux)) End If Next i1 i_b(14 + j1, c) = aux / (TN * (POBRESA ^ AV ERSION(j1, 3))) 'FGT NO_FGT1: Next j1 NO_FGT: NO_POBRESA: If NI = 0 Then GoTo NO_VAR1 '''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''' 'Índexs de concentració: absoluta i relativa 'Índexs de progressivitat: kakwani i suits 'Índexs de redistribució: Reynolds-Smolensky '''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''' pes1 = 0 pes2 = 0 cr = 0 For i1 = 1 To N iaux = IND(i1, 1) pes1 = pes1 + PES(iaux) pes2 = pes1 / TN cr = cr * (1 - PES(iaux) / pes1) + (XY(iaux , 1) * PES(iaux) / pes1) For i = 1 To NI ci(i) = ci(i) * (1 - PES(iaux) / pes1) + (XY(iaux, i + 1) * (PES(iaux) / pes1)) d1i(iaux, i) = 2 * pes1 * (XY(iaux, i + 1) - ci(i)) d1i_(i) = d1i_(i) + (d1i(iaux, i) * PES (iaux)) ddi(iaux, i) = XY(iaux, 1) * (mi(i) - c i(i) * pes2) + XY(iaux, i + 1) * cr * pes2 ddi_(i) = ddi_(i) + (ddi(iaux, i) * PES (iaux)) Next i Next i1 For i = 1 To NI md1i(i) = d1i_(i) / (TN ^ 2) mddi(i) = ddi_(i) / TN k = 6 * (i - 1) i_b(k + 18, c) = (md1i(i) / (2 * mi(i))) 'Conce ntració i_b(k + 19, c) = (1 / mr) * ((mddi(i) / mi( i)) - mddr) 'Conc. relat. i_b(k + 20, c) = i_b(k + 18, c) - i_b(1, c) 'Kakwa ni i_b(k + 21, c) = i_b(k + 19, c) - i_b(1, c) 'Suits Next i If Not II(5, 1) And Not II(6, 1) Then GoTo NO_REDIS TRIBUCIO j = 0 For i = 1 To NI j = j + 1 k = NI + 1 + j For i1 = 1 To N iaux = IND(i1, 1) mk(i) = mk(i) + (XY(iaux, k) * PES(iaux )) Next i1 mk(i) = mk(i) / TN For l = IIf(II(5, 1), 1, 2) To IIf(II(6, 1) , 2, 1) k = NI + j + 1 If l = 1 Then k1 = 1 If l = 2 Then k1 = k pes1 = 0 For i1 = 1 To N iaux = IND(i1, k1) pes1 = pes1 + PES(iaux) ck(i) = ck(i) * (1 - PES(iaux) / pe s1) + (XY(iaux, k) * (PES(iaux) / pes1)) d1k(iaux, i, l) = 2 * pes1 * (XY(ia ux, k) - ck(i)) d1k_(i, l) = d1k_(i, l) + (d1k(iaux , i, l) * PES(iaux)) Next i1 Next l Next i For i = 1 To NI k = 6 * (i - 1) For l = IIf(II(5, 1), 1, 2) To IIf(II(6, 1) , 2, 1) md1k(i, l) = d1k_(i, l) / (TN ^ 2) aux = ((md1k(i, l) / (2 * mk(i)))) i_b(k + 21 + l, c) = i_b(1, c) - aux 'Reyno lds-Smolensky Next l Next i NO_REDISTRIBUCIO:

Page 193: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

192

If Not IVAR(1) And Not IVAR(2) And Not IVAR(3) Then GoTo NO_VAR1 ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' 'Índexs de concentració, progressivitat i redis tribució: variàncies ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''' For i = 1 To NI For i1 = 1 To N iaux = IND(i1, 1) d1ai(i) = (i_b(6 * (i - 1) + 18, c) * X Y(iaux, i + 1)) - _ (((d1i(iaux, i) / TN) - (XY(i aux, i + 1) - mi(i)))) s1d1i(i) = s1d1i(i) + (d1ai(i) * PES(ia ux)) s2d1i(i) = s2d1i(i) + ((d1ai(i) ^ 2) * PES(iaux)) s3d1i(i) = s3d1i(i) + (d1ar(iaux) * d1a i(i) * PES(iaux)) ddia(i, 1) = i_b(6 * (i - 1) + 18, c) * XY(iaux, 1) ddia(i, 1) = ddia(i, 1) + ((mddi(i) / ( mi(i) ^ 2)) * XY(iaux, i + 1)) ddia(i, 1) = ddia(i, 1) - ((2 / mi(i)) * ddi(iaux, i)) ddia(i, 1) = ddia(i, 1) + (2 * ddr(iaux )) s1dd(i, 1) = s1dd(i, 1) + (ddia(i, 1) * PES(iaux)) s2dd(i, 1) = s2dd(i, 1) + ((ddia(i, 1) ^ 2) * PES(iaux)) ddia(i, 2) = ddia(i, 1) - (i_b(6 * (i - 1) + 19, c) * XY(iaux, 1)) ddia(i, 2) = ddia(i, 2) + (i_b(6 * (i - 1) + 21, c) * XY(iaux, 1)) ddia(i, 2) = ddia(i, 2) + ((d1r(iaux) / TN) - (XY(iaux, 1) - mr)) s1dd(i, 2) = s1dd(i, 2) + (ddia(i, 2) * PES(iaux)) s2dd(i, 2) = s2dd(i, 2) + ((ddia(i, 2) ^ 2) * PES(iaux)) Next i1 s1dd(i, 1) = s1dd(i, 1) s2dd(i, 1) = s2dd(i, 1) s1dd(i, 2) = s1dd(i, 2) s2dd(i, 2) = s2dd(i, 2) vd1i(i) = ((s2d1i(i) - ((s1d1i(i) ^ 2) / TN )) / (TN - 1)) / (N * (mi(i) ^ 2)) vcd1i(i) = ((s3d1i(i) - (s1d1r * s1d1i(i) / TN)) / (TN - 1)) / (N * mr * mi(i)) vdd(i, 1) = ((s2dd(i, 1) - ((s1dd(i, 1) ^ 2 ) / TN)) / (TN - 1)) / (N * (mr ^ 2)) vdd(i, 2) = ((s2dd(i, 2) - ((s1dd(i, 2) ^ 2 ) / TN)) / (TN - 1)) / (N * (mr ^ 2)) k = 6 * (i - 1) vindexs(k + 18, c) = vd1i(i) 'var. Concentració vindexs(k + 19, c) = vdd(i, 1) 'var. Conc. relativa vindexs(k + 20, c) = vd1r + vd1i(i) - (2 * vcd1i(i)) 'var. Kakwani vindexs(k + 21, c) = vdd(i, 2) 'var. Suits Next i If Not II(5, 1) Then GoTo NO_VAR1 j = 0 For i = 1 To NI j = j + 1 k = NI + 1 + j For i1 = 1 To N iaux = IND(i1, 1) d1ak(i) = (((md1k(i, 1) / (2 * mk(i)))) * XY(iaux, k)) - _ (((d1k(iaux, i, 1) / TN) - (X Y(iaux, k) - mk(i)))) s1d1k(i) = s1d1k(i) + (d1ak(i) * PES(ia ux)) s2d1k(i) = s2d1k(i) + ((d1ak(i) ^ 2) * PES(iaux)) s3d1k(i) = s3d1k(i) + (d1ar(iaux) * d1a k(i) * PES(iaux)) Next i1 vd1k(i) = ((s2d1k(i) - ((s1d1k(i) ^ 2) / TN )) / (TN - 1)) / (N * (mk(i) ^ 2)) vcd1k(i) = ((s3d1k(i) - (s1d1r * s1d1k(i) / TN)) / (TN - 1)) / (N * mr * mk(i)) aux = vd1r + vd1k(i) - (2 * vcd1k(i)) vindexs(6 * (i - 1) + 21 + 1, c) = aux 'var. Reynolds-Smolensky Next i NO_VAR1: Next c ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''' 'Open "C:\PROYECTOS\IndicesJordi\Program\Bootstrap_ t_results.txt" For Output As #200 'Write #200, "gini", "ginib", "vginib", _ ' "kakwani1", "kakwani1b", "vkakwani1b", _ ' "suits1", "suits1b", "vsuits1b", _ ' "kakwani2", "kakwani2b", "vkakwani2b", _ ' "suits2", "suits2b", "vsuits2b" 'For i1 = 0 To rboot ' Write #200, i_b(1, 0), i_b(1, i1), vindexs(1, i1), _ ' i_b(20, 0), i_b(20, i1), vindexs(2 0, i1), _ ' i_b(21, 0), i_b(21, i1), vindexs(2 1, i1), _

Page 194: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

193

' i_b(26, 0), i_b(26, i1), vindexs(2 6, i1), _ ' i_b(27, 0), i_b(27, i1), vindexs(2 7, i1) 'Next i1 'Close #200 ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''''''''' '''''''''''''''''''''''' 'Recuperació dels Índexs '''''''''''''''''''''''' For k = 1 To (6 * NI) + 17 INDEXS(k, 1) = i_b(k, 0) Next k If Not IVAR(1) And Not IVAR(2) And Not IVAR(3) Then GoTo NO_VAR2 ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''' 'Recuperació de les variàncies i càlcul dels interv als de confiança ''''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''' If IVAR(1) Or IVAR(2) Then aux = Application.Worksh eetFunction.Norm_S_Inv(1 - (SIG / 2)) If IVAR(1) Then 'asimptòtic For k = 1 To (6 * NI) + 17 If vindexs(k, 0) = 0 Then GoTo SVAR1 INDEXS(k, 2) = Sqr(vindexs(k, 0)) INDEXS(k, 3) = INDEXS(k, 1) - aux * INDEXS(k , 2) INDEXS(k, 4) = INDEXS(k, 1) + aux * INDEXS(k , 2) SVAR1: Next k ElseIf IVAR(2) Then 'bootstrap ReDim sumas(1 To (6 * NI) + 17, 1 To 2) As Doubl e For k = 1 To (6 * NI) + 17 If i_b(k, 0) = 0 Then GoTo SVAR2 If k = 10 Then GoTo SVAR2 For i1 = 1 To REP_BOOT sumas(k, 1) = sumas(k, 1) + i_b(k, i1) sumas(k, 2) = sumas(k, 2) + (i_b(k, i1) ^ 2) Next i1 INDEXS(k, 2) = Sqr(((sumas(k, 2) - ((sumas(k , 1) ^ 2) / REP_BOOT)) / (REP_BOOT - 1))) INDEXS(k, 3) = INDEXS(k, 1) - aux * INDEXS(k , 2) INDEXS(k, 4) = INDEXS(k, 1) + aux * INDEXS(k , 2) SVAR2: Next k ElseIf IVAR(3) Then 'bootstrap-t ReDim maux(1 To REP_BOOT) As Double, sumas(1 To (6 * NI) + 17, 1 To 2) As Double For k = 1 To (6 * NI) + 17 If i_b(k, 0) = 0 Then GoTo SVAR3 If k = 10 Then GoTo SVAR3 For i1 = 1 To REP_BOOT sumas(k, 1) = sumas(k, 1) + i_b(k, i1) sumas(k, 2) = sumas(k, 2) + (i_b(k, i1) ^ 2) Next i1 If vindexs(k, 0) = 0 Then GoTo SVAR3 For i1 = 1 To REP_BOOT maux(i1) = (i_b(k, i1) - INDEXS(k, 1)) / Sqr(vindexs(k, i1)) Next i1 INDEXS(k, 2) = Application.WorksheetFunction .Percentile_Inc(maux, SIG / 2) INDEXS(k, 3) = Application.WorksheetFunction .Percentile_Inc(maux, 1 - (SIG / 2)) INDEXS(k, 4) = INDEXS(k, 1) - INDEXS(k, 3) * Sqr(vindexs(k, 0)) INDEXS(k, 5) = INDEXS(k, 1) - INDEXS(k, 2) * Sqr(vindexs(k, 0)) aux = Sqr(((sumas(k, 2) - ((sumas(k, 1) ^ 2) / REP_BOOT)) / (REP_BOOT - 1))) INDEXS(k, 6) = INDEXS(k, 1) - INDEXS(k, 3) * aux INDEXS(k, 7) = INDEXS(k, 1) - INDEXS(k, 2) * aux SVAR3: Next k End If NO_VAR2: '''''''''''''''''''''''''''''''''''''' 'ESCRIPTURA INDEXS: RENDES o DESPESES' '''''''''''''''''''''''''''''''''''''' titol1 = IIf(NPES <> 0, "(Cálculos elevados)", "") & _ IIf(N > 15000, "", IIf(Not IVAR(1), " (Rep licaciones=" & REP_BOOT & ")", "")) opcio = 40 If IVAR(1) Then opcio = 41 If IVAR(2) Then opcio = 42 If IVAR(3) Then opcio = 43 If Not IVAR(1) And Not IVAR(2) And Not IVAR(3) Then dimR = 0

Page 195: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

194

Else If Not IVAR(3) Then dimR = 3 Else dimR = 6 End If k = 0 For j = 1 To 17 If IR(j, 1) Then k = k + 1 Next j ReDim R(1 To k + 2, 1 To 5 + dimR) R(1, 1) = "HIPÓTESIS" R(1, 3) = "INDICE" R(1, 5) = "Valor" If IVAR(1) Or IVAR(2) Then R(1, 6) = "Err. Est." & Chr(10) & IIf(IVAR(1), " asintótico", "'bootstrap'") R(1, 7) = "Interv. confianza " & Format(1 - SIG , "##%") R(2, 7) = "lim. inf." R(2, 8) = "lim. sup." ElseIf IVAR(3) Then R(1, 6) = "Percentiles 'bootstrap-t'" R(1, 8) = "Interv. 'asintótico' " & Format(1 - SIG, "##%") R(1, 10) = "Interv. 'boostrap' " & Format(1 - S IG, "##%") R(2, 6) = "< " & Format(SIG / 2, IIf(SIG = 0.1 O r SIG = 0.2, "0%", "0.0%")) R(2, 7) = "> " & Format(1 - (SIG / 2), IIf(SIG = 0.1 Or SIG = 0.2, "0%", "0.0%")) R(2, 8) = "lim. inf." R(2, 9) = "lim. sup." R(2, 10) = "lim. inf." R(2, 11) = "lim. sup." End If k = 0 For j = 1 To 17 If IR(j, 1) Then k = k + 1 If j = 1 Then R(k + 2, 1) = "DESIGUALDAD" If j = 8 Then R(k + 2, 1) = "ENTROPÍA" If j = 10 Then R(k + 2, 1) = "POBREZA" R(k + 2, 3) = IR(j, 2) R(k + 2, 5) = INDEXS(j, 1) If IVAR(1) Or IVAR(2) Or IVAR(3) Then For i = 1 To IIf(IVAR(3), 6, 3) R(k + 2, 5 + i) = INDEXS(j, i + 1) Next i End If End If Next j Call M7_ESCRIPTURA(opcio, "ÍNDICES SOBRE RENTA o GA STO" & titol1) '''''''''''''''''''''''''''''''''''''''''''''' 'ESCRIPTURA INDEXS: IMPOSTOS o TRANSFERÈNCIES' '''''''''''''''''''''''''''''''''''''''''''''' If NI > 0 Then opcio = 50 If IVAR(1) Then opcio = 51 If IVAR(2) Then opcio = 52 If IVAR(3) Then opcio = 53 k = 0 For j = 1 To 6 If II(j, 1) Then k = k + 1 Next j ReDim R(1 To (NI * k) + 2, 1 To 5 + dimR) R(1, 1) = "IMPUESTO" & Chr(10) & "o" & Chr(10) & "TRANSF." R(1, 2) = "INDICE" R(2, 5) = "Valor" If IVAR(1) Or IVAR(2) Then R(2, 6) = "Err. est." & Chr(10) & IIf(IVAR(1) , "asintótico", "'bootstrap'") R(1, 7) = "Interv. confianza " & Format(1 - SIG, "##%") R(2, 7) = "lim. inf." R(2, 8) = "lim. sup." ElseIf IVAR(3) Then R(1, 6) = "Percentiles 'bootstrap-t'" R(1, 8) = "Interv. 'asintótico' " & Format(1 - SIG, "##%") R(1, 10) = "Interv. 'boostrap' " & Format(1 - SIG, "##%") R(2, 6) = "< " & Format(SIG / 2, IIf(SIG = 0. 1 Or SIG = 0.2, "0%", "0.0%")) R(2, 7) = "> " & Format(1 - (SIG / 2), IIf(SI G = 0.1 Or SIG = 0.2, "0%", "0.0%")) R(2, 8) = "lim. inf." R(2, 9) = "lim. sup." R(2, 10) = "lim. inf."

Page 196: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

195

R(2, 11) = "lim. sup." End If l = 0 For j = 1 To 6 If II(j, 1) Then l = l + 1 For i = 1 To NI R(((i - 1) * k) + 3, 1) = LVAR(i + 1, 2) R(((i - 1) * k) + 2 + l, 2) = II(j, 2 ) R(((i - 1) * k) + 2 + l, 5) = INDEXS( 6 * (i - 1) + 17 + j, 1) If IVAR(1) Or IVAR(2) Or IVAR(3) Then For j1 = 1 To IIf(IVAR(3), 6, 3) R(((i - 1) * k) + 2 + l, j1 + 5) = INDEXS(6 * (i - 1) + 17 + j, j1 + 1) Next j1 End If Next i End If Next j Call M7_ESCRIPTURA(opcio, "ÍNDICES SOBRE IMPUEST OS O TRANSFERENCIAS " & titol1) End If End Sub Private Sub M7_ESCRIPTURA(opcio As Integer, titol1 As String) '''''''''''''''''''' 'ÍNDEXS: ESCRIPTURA' '''''''''''''''''''' Sheets(FULL_R).Activate ''''''''''''''''''''''''''''''''''''''''''''' 'opcio=1 ==> DESCRIPTIU ' 'opcio=11 ==> PERCENTILS ' 'opcio=12 ==> TIPUS EFECTIUS TOTALS' 'opcio=2 ==> DECILS ' 'opcio=3 ==> TIPUS EFECTIUS ' 'opcio=40,41,42,43 ==> INDEXS RENDES ' 'opcio=50,51,52,53 ==> INDEXS IMPOSTOS ' ''''''''''''''''''''''''''''''''''''''''''''' Dim c(1 To 2) As Integer, a As Integer, i As Intege r, i1 As Integer, j1 As Integer, k1 As Integer, _ l1 As Integer, l2 As Integer, l3 As Integer, l4 As Integer, l5 As Integer ''''''''''''''''''''''''''' 'ESCRIPTURA DELS RESULTATS' ''''''''''''''''''''''''''' c(1) = UBound(R, 1) c(2) = UBound(R, 2) Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 13)).Col umnWidth = 7.14 With Range(Cells(F - 2, 1), Cells(F + c(1) - 1, 13) ) With .Font .Name = "Arial" .Size = 7 End With .HorizontalAlignment = xlCenter .Interior.ColorIndex = 2 .RowHeight = 10 .VerticalAlignment = xlCenter End With With Cells(F - 1, 1) .Font.Bold = True .HorizontalAlignment = xlLeft .Value = titol1 End With With Range(Cells(F, 1), Cells(F + c(1) - 1, c(2))) .Borders.LineStyle = xlContinuous .Borders(xlEdgeLeft).LineStyle = xlNone .Borders(xlEdgeRight).LineStyle = xlNone .Interior.ColorIndex = 37 .Value = R End With ''''''''''''''''''''''''''''''''''''''''' 'Escriptura característica de cada opció' ''''''''''''''''''''''''''''''''''''''''' If opcio = 1 Then

Page 197: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

196

Range(Cells(F, 2), Cells(F + 2, c(2))).Font.Bold = True Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Font. Bold = True Range(Cells(F + 3, 1), Cells(F + c(1) - 1, 1)).H orizontalAlignment = xlLeft Range(Cells(F + 3, 2), Cells(F + c(1) - 1, c(2)) ).HorizontalAlignment = xlRight Range(Cells(F + 3, 2), Cells(F + c(1) - 1, c(2)) ).NumberFormat = "#,##0" Range(Cells(F, 1), Cells(F + 2, 1)).MergeCells = True Range(Cells(F, 2), Cells(F, 5)).MergeCells = Tru e Range(Cells(F, 6), Cells(F, 9)).MergeCells = Tru e Range(Cells(F + 1, 2), Cells(F + 2, 2)).MergeCel ls = True Range(Cells(F + 1, 3), Cells(F + 2, 3)).MergeCel ls = True Range(Cells(F + 1, 4), Cells(F + 1, 5)).MergeCel ls = True Range(Cells(F + 1, 6), Cells(F + 2, 6)).MergeCel ls = True Range(Cells(F + 1, 7), Cells(F + 2, 7)).MergeCel ls = True Range(Cells(F + 1, 8), Cells(F + 1, 9)).MergeCel ls = True Range(Cells(F + 3, 1), Cells(F + c(1) - 1, 1)).S hrinkToFit = True Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F, 2), Cells(F, c(2))).Borders(xlEdg eBottom).LineStyle = xlDouble Range(Cells(F + 2, 1), Cells(F + 2, c(2))).Borde rs(xlEdgeBottom).Weight = xlMedium Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium If NI > 0 Then With Range(Cells(F + c(1) - NI - 1, 1), Cells (F + c(1) - NI - 1, c(2))).Borders(xlEdgeBottom) .LineStyle = xlDash .Weight = xlMedium End With End If ElseIf opcio = 11 Then Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Font. Bold = True Range(Cells(F, 2), Cells(F + 1, c(2))).Font.Bold = True Range(Cells(F + 2, 2), Cells(F + c(1) - 1, c(2)) ).HorizontalAlignment = xlRight Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).H orizontalAlignment = xlLeft Range(Cells(F, 2), Cells(F + 1, c(2))).NumberFor mat = "##0%" Range(Cells(F + 2, 2), Cells(F + c(1) - 1, c(2)) ).NumberFormat = "#,##0" Range(Cells(F, 1), Cells(F + 1, 1)).MergeCells = True Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).S hrinkToFit = True Range(Cells(F, 2), Cells(F + 1, c(2))).Borders.L ineStyle = xlNone Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F + 1, 1), Cells(F + 1, c(2))).Borde rs(xlEdgeBottom).LineStyle = xlContinuous Range(Cells(F + 1, 1), Cells(F + 1, c(2))).Borde rs(xlEdgeBottom).Weight = xlMedium Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium If NI > 0 Then With Range(Cells(F + c(1) - NI - 1, 1), Cells (F + c(1) - NI - 1, c(2))).Borders(xlEdgeBottom) .LineStyle = xlDash .Weight = xlMedium End With End If ElseIf opcio = 12 Then Range(Cells(F, 1), Cells(F, c(2))).Font.Bold = T rue Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).F ont.Bold = True Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).H orizontalAlignment = xlLeft Range(Cells(F + 1, 2), Cells(F + c(1) - 1, c(2)) ).HorizontalAlignment = xlRight Range(Cells(F + 1, 2), Cells(F + c(1) - 1, c(2)) ).NumberFormat = "##0.000%" Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).S hrinkToFit = True Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F + 1, 1), Cells(F + 1, c(2))).Borde rs(xlEdgeTop).Weight = xlMedium Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium ElseIf opcio = 2 Then Range(Cells(F, 2), Cells(F + 1, c(2))).Font.Bold = True Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Font. Bold = True Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).H orizontalAlignment = xlLeft Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).W rapText = True Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Verti calAlignment = xlCenter Range(Cells(F, 2), Cells(F + 1, c(2))).NumberFor mat = "##0%" Range(Cells(F + 2, 2), Cells(F + c(1) - 1, c(2)) ).NumberFormat = "##0.000%" For j1 = 2 To c(1) Step 2 With Range(Cells(F + j1 - 1, 2), Cells(F + j 1 - 1, c(2))) .Borders(xlEdgeBottom).LineStyle = xlConti nuous .Borders(xlEdgeTop).LineStyle = xlDot .Font.Italic = True End With Next j1 For i1 = 3 To c(1) - 1 Step 2 Range(Cells(F + i1 - 1, 1), Cells(F + i1, 1) ).MergeCells = True Next i1 Range(Cells(F, 1), Cells(F + 1, 1)).MergeCells = True Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Borde rs(xlEdgeRight).LineStyle = xlContinuous Range(Cells(F + 1, 1), Cells(F + 1, c(2))).Borde rs(xlEdgeBottom).LineStyle = xlDash Range(Cells(F + 1, 1), Cells(F + 1, c(2))).Borde rs(xlEdgeBottom).LineStyle = xlContinuous

Page 198: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

197

Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F + 1, 1), Cells(F + 1, c(2))).Borde rs(xlEdgeBottom).Weight = xlMedium Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium If NI > 0 Then With Range(Cells(F + c(1) - NI - NI - 1, 1), Cells(F + c(1) - NI - NI - 1, c(2))).Borders(xlEdge Bottom) .LineStyle = xlDash .Weight = xlMedium End With End If If NI = 0 Then ActiveWindow.SelectedSheets.HPage Breaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 3 Then Range(Cells(F, 2), Cells(F, c(2))).Font.Bold = T rue Range(Cells(F, 1), Cells(F + c(1) - 1, 1)).Font. Bold = True Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).H orizontalAlignment = xlLeft Range(Cells(F + 1, 1), Cells(F + c(1) - 1, 1)).S hrinkToFit = True Range(Cells(F, 2), Cells(F, c(2))).NumberFormat = "##0%" Range(Cells(F + 1, 2), Cells(F + c(1) - 1, c(2)) ).NumberFormat = "##0.000%" Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eBottom).LineStyle = xlContinuous Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eBottom).Weight = xlMedium Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) ElseIf opcio = 40 Or opcio = 41 Or opcio = 42 Or op cio = 43 Then Range(Cells(F, 1), Cells(F + 1, c(2))).Font.Bold = True With Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 4)) .Font.Bold = True .HorizontalAlignment = xlLeft End With For i1 = 5 To 5 Range(Cells(F + 2, i1), Cells(F + c(1) - 1, i1)).NumberFormat = "0.0000" Next i1 If opcio <> 40 Then For i1 = 6 To 6 Range(Cells(F + 2, i1), Cells(F + c(1) - 1, i1)).NumberFormat = IIf(opcio <> 43, "0.000000", "0.0000") Next i1 For i1 = 7 To c(2) Range(Cells(F + 2, i1), Cells(F + c(1) - 1, i1)).NumberFormat = "0.0000" Next i1 End If Range(Cells(F, 1), Cells(F + 1, 2)).MergeCells = True Range(Cells(F, 3), Cells(F + 1, 4)).MergeCells = True Range(Cells(F, 5), Cells(F + 1, 5)).MergeCells = True If opcio = 41 Or opcio = 42 Then Range(Cells(F, 6), Cells(F + 1, 6)).MergeCell s = True Range(Cells(F, 7), Cells(F, 8)).MergeCells = True End If If opcio = 43 Then Range(Cells(F, 6), Cells(F, 7)).MergeCells = True Range(Cells(F, 8), Cells(F, 9)).MergeCells = True Range(Cells(F, 10), Cells(F, 11)).MergeCells = True End If l1 = 1 For j1 = 1 To 3 If IR(j1 + 1, 1) Then l1 = l1 + 1 'índexs gini extes Next j1 If l1 > 1 Then If opcio = 41 Or opcio = 43 Then With Range(Cells(F + 2 + 1, 6), Cells(F + 2 + l1 - 1, IIf(opcio = 41, 8, 11))) .Borders(xlInsideHorizontal).LineStyle = xlNone .Borders(xlInsideVertical).LineStyle = x lNone .Interior.Pattern = xlCrissCross .Value = "" End With End If End If l2 = 0 For j1 = 1 To 3 If IR(j1 + 4, 1) Then l2 = l2 + 1 'índexs atkinson Next j1 If l2 > 1 Then If opcio = 41 Or opcio = 43 Then For i1 = 1 To 3 If AVERSION(i1, 2) <> 1 Then With Range(Cells(F + 2 + l1 + i1 - 1, 6), Cells(F + 2 + l1 + i1 - 1, IIf(opcio = 41, 8 , 11))) .Borders(xlInsideHorizontal).Line Style = xlNone

Page 199: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

198

.Borders(xlInsideVertical).LineSt yle = xlNone .Interior.Pattern = xlCrissCross .Value = "" End With End If Next i1 End If End If Range(Cells(F + 2, 1), Cells(F + 2 + l1 + l2 - 1 , 2)).MergeCells = True If Not IR(9, 1) Then 'índexs entropia l3 = 1 Range(Cells(F + 2 + l1 + l2, 1), Cells(F + 2 + l1 + l2 + l3 - 1, 2)).MergeCells = True Else l3 = 2 Range(Cells(F + 2 + l1 + l2, 1), Cells(F + 2 + l1 + l2 + l3 - 1, 2)).MergeCells = True End If l4 = 0 l5 = 0 For j1 = 10 To 17 If IR(j1, 1) Then l4 = l4 + 1 'índexs pobresa If j1 >= 15 And IR(j1, 1) Then l5 = l5 + 1 'indexs FGT Next j1 If l4 <> 0 Then Range(Cells(F + 2 + l1 + l2 + l3, 1), Cells(F + 2 + l1 + l2 + l3 + l4 - 1, 2)).MergeCells = True Cells(F + 2 + l1 + l2 + l3, 5).NumberFormat = "#,##0" 'Umbral de pobresa" If opcio = 41 Or opcio = 43 Then With Range(Cells(F + 2 + l1 + l2 + l3, 6), Cells(F + 2 + l1 + l2 + l3 + 2, IIf(opcio = 41, 8, 11))) .Borders(xlBottom).LineStyle = xlNone .Borders(xlInsideHorizontal).LineStyle = xlNone .Borders(xlInsideVertical).LineStyle = x lNone .Interior.Pattern = xlCrissCross .Value = "" End With If l5 <> 0 Then With Range(Cells(F + c(1) - l5, 6), Cel ls(F + c(1) - 1, IIf(opcio = 41, 8, 11))) .Borders(xlBottom).LineStyle = xlNone .Borders(xlInsideHorizontal).LineStyl e = xlNone .Borders(xlInsideVertical).LineStyle = xlNone .Interior.Pattern = xlCrissCross .Value = "" End With End If End If If opcio = 42 Then With Range(Cells(F + 2 + l1 + l2 + l3, 6), Cells(F + 2 + l1 + l2 + l3, 8)) .Borders(xlEdgeTop).LineStyle = xlContin uous .Borders(xlBottom).LineStyle = xlNone .Borders(xlInsideHorizontal).LineStyle = xlNone .Borders(xlInsideVertical).LineStyle = x lNone .Interior.Pattern = xlCrissCross .Value = "" End With End If End If For i1 = 1 To c(1) - 2 Range(Cells(F + 2 + i1 - 1, 3), Cells(F + 2 + i1 - 1, 4)).MergeCells = True Next i1 Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F, 5), Cells(F, c(2))).Borders(xlEdg eBottom).LineStyle = xlContinuous Range(Cells(F + 2, 1), Cells(F + 2, c(2))).Borde rs(xlEdgeTop).LineStyle = xlContinuous Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium If NI = 0 Then ActiveWindow.SelectedSheets.HPage Breaks.Add (Cells(F + c(1), 1)) ElseIf opcio = 50 Or opcio = 51 Or opcio = 52 Or op cio = 53 Then Range(Cells(F, 1), Cells(F + 1, c(2))).Font.Bold = True With Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 4)) .Font.Bold = True .HorizontalAlignment = xlLeft End With Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).W rapText = True Range(Cells(F + 2, 1), Cells(F + c(1) - 1, 1)).H orizontalAlignment = xlCenter For i1 = 5 To 5 Range(Cells(F + 2, i1), Cells(F + c(1) - 1, i1)).NumberFormat = "0.0000" Next i1 If opcio <> 50 Then For i1 = 6 To 6 Range(Cells(F + 2, i1), Cells(F + c(1) - 1, i1)).NumberFormat = IIf(opcio = 53, "0.0000", "0 .000000") Next i1 For i1 = 7 To c(2)

Page 200: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

199

Range(Cells(F + 2, i1), Cells(F + c(1) - 1, i1)).NumberFormat = "0.0000" Next i1 End If Range(Cells(F, 1), Cells(F + 1, 1)).MergeCells = True Range(Cells(F, 2), Cells(F + 1, 4)).MergeCells = True Range(Cells(F, 5), Cells(F + 1, 5)).MergeCells = True If opcio = 51 Or opcio = 52 Then Range(Cells(F, 6), Cells(F + 1, 6)).MergeCell s = True Range(Cells(F, 7), Cells(F, 8)).MergeCells = True End If If opcio = 53 Then Range(Cells(F, 6), Cells(F, 7)).MergeCells = True Range(Cells(F, 8), Cells(F, 9)).MergeCells = True Range(Cells(F, 10), Cells(F, 11)).MergeCells = True End If For i1 = 2 To c(1) - 1 With Range(Cells(F + i1, 2), Cells(F + i1, 4 )) .HorizontalAlignment = xlLeft .MergeCells = True End With Next i1 If opcio = 51 Or opcio = 53 Then For i = 1 To NI If II(6, 1) Then 'R eynolds-Smolensky (modificado) With Range(Cells(F + 2 + (6 * i) - 1, 6), Cells(F + 2 + (6 * i) - 1, IIf(opcio = 51, 8, 1 1))) .Borders(xlInsideHorizontal).LineSty le = xlNone .Borders(xlInsideVertical).LineStyle = xlNone .Interior.Pattern = xlCrissCross .Value = "" End With End If Next i End If Range(Cells(F, 1), Cells(F, c(2))).Borders(xlEdg eTop).Weight = xlMedium Range(Cells(F, 5), Cells(F, c(2))).Borders(xlEdg eBottom).LineStyle = xlContinuous Range(Cells(F + 2, 1), Cells(F + 2, c(2))).Borde rs(xlEdgeTop).LineStyle = xlContinuous Range(Cells(F + c(1) - 1, 1), Cells(F + c(1) - 1 , c(2))).Borders(xlEdgeBottom).Weight = xlMedium For i = 1 To NI j1 = ((i - 1) * ((c(1) - 2) / NI)) k1 = (i * ((c(1) - 2) / NI)) - 1 With Range(Cells(F + 2 + j1, 1), Cells(F + 2 + k1, 1)) .MergeCells = True .VerticalAlignment = xlCenter End With If i > 1 Then With Range(Cells(F + 2 + j1, 1), Cells(F + 2 + j1, c(2))).Borders(xlEdgeTop) .LineStyle = xlDash .Weight = xlMedium End With End If Next i ActiveWindow.SelectedSheets.HPageBreaks.Add (Cel ls(F + c(1), 1)) End If F = F + c(1) + 2 Sheets(FULL).Activate End Sub Private Sub M7_GRAFICS(ds, ts) ''''''''''''''''' 'ÍNDEXS: GRÀFICS' ''''''''''''''''' Dim i As Integer, j As Integer, k As Integer, l As Integer, fila As Integer, col As Integer, m As Doub le, _ ncells(1 To 2) As Integer, ngrafics(1 To 2) As Integer ReDim r_g(0 To NI + NI + 1) As Range ngrafics(1) = 0 ngrafics(2) = 0 If GR(2) Then ngrafics(1) = NI If GR(1) And Not GR(2) Then ngrafics(1) = 1 If GR(3) Then ngrafics(2) = NI ncells(1) = 0 ncells(2) = 0 If GR(1) Or GR(2) Then ncells(1) = IIf(ngrafics(1) < 3, 19, IIf(ngrafics(1) < 5, 38, IIf(ngrafics(1) < 7, 57, 76))) If GR(3) Then ncells(2) = IIf(ngrafics(2) < 3, 19, IIf(ngrafics(2) < 5, 38, IIf(ngrafics(2) < 7, 57, 7 6)))

Page 201: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

200

Sheets(FULL_R).Activate With Range(Cells(F - 2, 1), Cells(F - 3 + ncells(1) + ncells(2), 13)) .Interior.ColorIndex = 2 .RowHeight = 11 End With For j = 1 To 13 If j < 11 Then Cells(F, j) = (j - 1) / 10 'noms dels decils, s'esborraran If j = 11 Then Cells(F, j) = 0.95 If j = 12 Then Cells(F, j) = 0.98 If j = 13 Then Cells(F, j) = 1 Next j Set r_g(0) = Range(Cells(F, 1), Cells(F, 13)) For i = 1 To 1 + IIf(GR(2), NI, 0) Cells(F + i, 1) = 0 For j = 1 To 12 Cells(F + i, j + 1) = ds(2 * i, j) 'valors dels decils de renda i impostos, s'esborraran Next j Set r_g(i) = Range(Cells(F + i, 1), Cells(F + i , 13)) Next i If GR(3) Then For i = 1 To NI Cells(F + 1 + IIf(GR(2), NI, 0) + i, 1) = 0 For j = 1 To 12 Cells(F + 1 + IIf(GR(2), NI, 0) + i, j + 1) = ts(i, j) 'valors dels decils dels tipus, s'es borraran Next j Set r_g(1 + NI + i) = Range(Cells(F + 1 + II f(GR(2), NI, 0) + i, 1), _ Cells(F + 1 + II f(GR(2), NI, 0) + i, 13)) Next i End If If Not GR(1) And Not GR(2) Then GoTo NO_LORENZ '''''''''''''''''''''''''''''''''' 'GRÀFICS de Lorenz i Concentració' '''''''''''''''''''''''''''''''''' For i = 1 To ngrafics(1) Charts.Add With ActiveChart .ChartType = xlXYScatterSmoothNoMarkers For k = 1 To 2 + IIf(GR(2), 2, 0) .SeriesCollection.NewSeries With .SeriesCollection(k) With .Border .ColorIndex = IIf(k = 1, 1, IIf(k = 2 , 32, 3)) .Weight = xlMedium If k = 4 Then .LineStyle = xlDot End With If k = 1 Then .Name = "Equidad" .Values = r_g(0) .XValues = r_g(0) ElseIf k = 2 Then .Name = LVAR(1, 2) .Values = r_g(1) .XValues = r_g(0) ElseIf k = 3 Then .Name = LVAR(i + 1, 2) .Values = r_g(i + 1) .XValues = r_g(0) ElseIf k = 4 Then .Name = LVAR(i + 1, 2) & " (relativa )" .Values = r_g(i + 1) .XValues = r_g(1) End If End With Next k For k = 1 To 2 With .Axes(IIf(k = 1, xlCategory, xlValue )) .HasMajorGridlines = True .HasDisplayUnitLabel = False .MinorUnit = 0.1 .MajorUnit = 0.1 .MinimumScale = 0 .MaximumScale = 1 .TickLabels.Font.Bold = True .TickLabels.Font.Name = "Calibri" .TickLabels.Font.Size = 7 .TickLabels.NumberFormat = "0%" End With

Page 202: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

201

Next k .HasTitle = True With .ChartTitle .Characters.Text = IIf(GR(2), "Curvas de Lo renz, concentración y concentración relativa", _ "Curva de Lor enz") .Font.Bold = True .Font.Name = "Calibri" .Font.Size = 7.5 .Top = 0 End With If GR(2) Then With .Legend .Border.LineStyle = xlNone .Font.Bold = True .Font.Name = "Calibri" .Font.Size = 5.5 For k = .LegendEntries.Count To IIf(GR(2 ), 5, 3) Step -1 .LegendEntries(k).Delete Next k .LegendEntries(1).Delete .Position = xlLegendPositionBottom End With Else .HasLegend = False End If With .PlotArea .Interior.ColorIndex = 2 .Left = 0 .Top = 20 .Width = 805 .Height = 410 End With .Location Where:=xlLocationAsObject, Name:=FU LL_R ''''''''''''''''''''''''''''''''''''''''''' 'Definició d'alçada i amplada dels gràfics' ''''''''''''''''''''''''''''''''''''''''''' With Worksheets(FULL_R) .ChartObjects(1).Height = 196 .ChartObjects(1).Width = 234 End With ''''''''''''''''''''''''''''''''''''' 'Reconversió dels gràfics en imatges' ''''''''''''''''''''''''''''''''''''' ActiveSheet.ChartObjects(1).CopyPicture ActiveWindow.Visible = False fila = IIf(i < 3, F - 1, IIf(i < 5, F + 18, I If(i < 7, F + 37, F + 56))) col = IIf(i = 1 Or i = 3 Or i = 5 Or i = 7, 2 , 7) Cells(fila, col).Select ActiveSheet.Paste Worksheets(FULL_R).ChartObjects(1).Delete End With Next i ActiveWindow.SelectedSheets.HPageBreaks.Add (Cells( F - 2 + ncells(1) + ncells(2), 1)) NO_LORENZ: '''''''''''''''''' 'GRÀFICS de Tipus' '''''''''''''''''' If Not GR(3) Then GoTo NO_TIPUS For i = 1 To NI Charts.Add With ActiveChart .ChartType = xlXYScatterSmoothNoMarkers .SeriesCollection.NewSeries With .SeriesCollection(1) With .Border .ColorIndex = 32 .Weight = xlMedium End With .MarkerStyle = xlNone .Name = LVAR(i + 1, 2) .Values = r_g(NI + 1 + i) .XValues = r_g(0) End With m = Round(Application.max(r_g(NI + 1 + i)), 5 )

Page 203: MicroEconometria (Código Fuente)diposit.ub.edu/dspace/bitstream/2445/55847/3...MsgBox "El valor del punto de corte " & i1 & " es incorrecto.", vbCritical + vbOKOnly, TITOL Exit Sub

MicroEconometria

202

For k = 1 To 2 With .Axes(IIf(k = 1, xlCategory, xlValue )) .HasMajorGridlines = True .HasDisplayUnitLabel = False .MinorUnit = IIf(k = 1, 0.1, m / 10) .MajorUnit = IIf(k = 1, 0.1, m / 10) .MinimumScale = 0 .MaximumScale = IIf(k = 1, 1, m) .TickLabels.Font.Bold = True .TickLabels.Font.Name = "Calibri" .TickLabels.Font.Size = 7 .TickLabels.NumberFormat = "0%" End With Next k .HasTitle = True With .ChartTitle .AutoScaleFont = False .Characters.Text = "Tipo Efectivo: " & LVAR (i + 1, 2) & " s/" & LVAR(1, 2) .Font.Bold = True .Font.Name = "Calibri" .Font.Size = 8.5 .Top = 0 End With .HasLegend = False With .PlotArea .Interior.ColorIndex = 2 .Left = 0 .Top = 20 .Width = 805 .Height = 440 End With .Location Where:=xlLocationAsObject, Name:=FU LL_R ''''''''''''''''''''''''''''''''''''''''''' 'Definició d'alçada i amplada dels gràfics' ''''''''''''''''''''''''''''''''''''''''''' With Worksheets(FULL_R) .ChartObjects(1).Height = 196 .ChartObjects(1).Width = 234 End With ''''''''''''''''''''''''''''''''''''' 'Reconversió dels gràfics en imatges' ''''''''''''''''''''''''''''''''''''' ActiveSheet.ChartObjects(1).CopyPicture ActiveWindow.Visible = False fila = IIf(i < 3, F + ncells(1) - 1, IIf(i < 5, F + ncells(1) + 18, _ IIf(i < 7, F + ncells(1) + 37, F + nce lls(1) + 56))) col = IIf(i = 1 Or i = 3 Or i = 5 Or i = 7, 2 , 7) Cells(fila, col).Select ActiveSheet.Paste Worksheets(FULL_R).ChartObjects(1).Delete End With Next i ActiveWindow.SelectedSheets.HPageBreaks.Add (Cells( F - 2 + ncells(1) + ncells(2), 1)) NO_TIPUS: For i = 1 To Worksheets(FULL_R).Shapes.Count col = IIf(i = 1 Or i = 3 Or i = 5 Or i = 7 Or i = 9 Or i = 11 Or i = 13 Or i = 15 Or _ i = 17 Or i = 19 Or i = 21 Or i = 23 Or i = 25 Or i = 27 Or i = 29 Or i = 31 Or _ i = 33 Or i = 35 Or i = 37 Or i = 39 Or i = 41 Or i = 43 Or i = 45 Or i = 47 Or _ i = 49 Or i = 51 Or i = 53 Or i = 55 Or i = 57 Or i = 59 Or i = 61 Or i = 63, 15, 265) Worksheets(FULL_R).Shapes(i).Left = col Next i For i = 0 To 1 + IIf(GR(2), NI, 0) + IIf(GR(3), NI, 0) For j = 1 To 13 Cells(F + i, j) = "" Next j Next i F = F + ncells(1) + ncells(2) Sheets(FULL).Activate End Sub