Assignment 23 March Codes
Assignment 23 March Codes
Sub Delete_Errors_Firms()
lc = Sheets("RI").Cells(1, Columns.Count).End(xlToLeft).Column
For i = lc To 2 Step -1
Application.DisplayAlerts = False
Sheets("RI").Columns(i).EntireColumn.Delete
Sheets("MV").Columns(i).EntireColumn.Delete
Sheets("P").Columns(i).EntireColumn.Delete
Sheets("VO").Columns(i).EntireColumn.Delete
Sheets("BM").Columns(i).EntireColumn.Delete
Application.DisplayAlerts = True
End If
Next i
End Sub
Dim k As Integer
Dim m As Integer
lr = Sheets("RI").Cells(Rows.Count, 1).End(xlUp).Row
Last = 0
start = 0
m=2
For j = 2 To lr
If j <> 2 Then
m=m+1
End If
End If
Last = Last + 1
start = Last + 1
Next
Application.ScreenUpdating = True
End Sub
Sub Dret()
Application.ScreenUpdating = False
lr = Sheets("RI").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("RI").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "DRL"
Range(Sheets("DRL").Cells(1, 1), Sheets("DRL").Cells(1, lc)).Value = _
Sheets("RI").Activate
For j = 2 To lc
For i = 2 To lr
ret = ""
Else
End If
Next
Next
Application.ScreenUpdating = True
End Sub
Sub Daily_Amihud()
Dim lr As Integer
Dim lc As Integer
Dim j As Integer
Dim i As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Sheets("P").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("P").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "DAMI"
Sheets("P").Activate
For j = 2 To lr
For i = 2 To lc
If mat1 <> 0 And mat2 <> 0 And mat3 <> 0 And mat1 <> "" And mat2 <> "" And mat3 <> ""
Then
End If
Next i
Next j
Sheets("DAMI").Columns.AutoFit
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub Lesmond()
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("DRL").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "LESDE"
For Col = 2 To lc
For Row = 2 To lr
Count = Application.WorksheetFunction.Count(n)
If Count = 0 Or Count - Count0 <= 5 Then ' traded more than 5 days in any month
Else
End If
End If
Next Row
Next Col
Application.ScreenUpdating = True
End Sub
Sub AmihudM()
Application.ScreenUpdating = False
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("DAMI").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "AmihudM"
For Col = 2 To lc
For Row = 2 To lr
Sum = Application.WorksheetFunction.Sum(n)
Count = Application.WorksheetFunction.Count(n)
If Count >= 5 Then ' traded more than 5 days in any month
Else
End If
End If
Next Row
Next Col
End Sub
Sub MR()
Dim lr As Integer
Dim lc As Integer
Dim k As Integer
Dim m As Integer
Application.ScreenUpdating = False
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("RI").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "Ret"
Sheets("Ret").Activate
k=2
For i = 2 To lc
r=2
For m = 2 To lr - 1
x = Sheets("N").Cells(m, 2).Value
y = Sheets("N").Cells(m + 1, 1).Value
P1 = Sheets("RI").Cells(x, k).Value
P2 = Sheets("RI").Cells(y, k).Value
If P1 <> "" And P1 <> 0 And P2 <> "" And P2 <> 0 Then
Else
End If
r=r+1
Next
k=k+1
Next
For k = 2 To lc
For g = 2 To lr - 1
x = Sheets("N").Cells(g, 2).Value
y = Sheets("N").Cells(g + 1, 1).Value
Count = Application.WorksheetFunction.Count(n)
End If
End If
Next
Next
Application.ScreenUpdating = True
End Sub
Sub MMV()
Dim lr As Integer
Dim lc As Integer
Dim c As Integer
Dim r As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("MMV").Delete
Application.DisplayAlerts = True
Application.Calculation = xlCalculationManual
Application.Calculation = xlCalculationManual
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("MV").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "MMV"
For Col = 2 To lc
For Row = 3 To lr
y = Sheets("N").Cells(Row, 1).Value
n1 = Sheets("MV").Cells(y, Col).Value
Sheets("MMV").Cells(Row - 1, Col).Value = n1
Next Row
Next Col
Application.ScreenUpdating = True
End Sub
Sub MVO()
Dim lr As Integer
Dim lc As Integer
Dim c As Integer
Dim r As Integer
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Sheets("MVO").Delete
Application.DisplayAlerts = True
Application.Calculation = xlCalculationManual
Application.Calculation = xlCalculationManual
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("VO").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "MVO"
For Col = 2 To lc
For Row = 3 To lr
y = Sheets("N").Cells(Row, 1).Value
n1 = Sheets("VO").Cells(y, Col).Value
Sheets("MVO").Cells(Row - 1, Col).Value = n1
Next Row
Sheets("MVO").Cells(1, Col).Value = Sheets("VO").Cells(1, Col).Value
Next Col
Application.ScreenUpdating = True
End Sub
Sub MBM()
Dim lr As Integer
Dim lc As Integer
Dim c As Integer
Dim r As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("BM").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "MBM"
For Col = 2 To lc
For Row = 3 To lr
y = Sheets("N").Cells(Row, 1).Value
n1 = Sheets("BM").Cells(y, Col).Value
Sheets("MBM").Cells(Row - 1, Col).Value = n1
Next Row
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Dim lr As Integer
Dim lc As Integer
Dim c As Integer
Dim r As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lc = Sheets("DRL").Cells(1, Columns.Count).End(xlToLeft).Column
lr = Sheets("DRL").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("DRL").Activate
k=2
For c = 2 To lc
m=2
For r = 2 To lr
x = Sheets("N").Cells(m, 2).Value
y = Sheets("N").Cells(m + 1, 1).Value
End If
m=m+1
Next r
k=k+1
Next c
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub Panel_Corr()
Dim lr As Integer
Dim c As Integer
Dim g As Integer
Dim ID As Integer
Dim x As Variant
Dim D As Date
Application.ScreenUpdating = False
lr = Sheets("Ret").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("Ret").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "Panel"
x=2
If Ret_pak <> "" And Illiq_pk <> "" And MV_pak <> "" And MVO_pak And BM_pak <> "" _
And Lesm_pak <> "" Then ' take common firms that have all data
Sheets("Panel").Cells(x, 1).Value = D
Sheets("Panel").Cells(x, 2).Value = ID
End If
ID = ID + 1
Next c
End Sub
Sub LMBM()
Dim lr As Integer
Dim lc As Integer
Dim c As Integer
Dim r As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("BM").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "LMBM"
For Col = 2 To lc
For Row = 3 To lr
y = Sheets("N").Cells(Row, 1).Value
n1 = Sheets("BM").Cells(y, Col).Value
Next Row
Next Col
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Sub LMMV()
Dim lr As Integer
Dim lc As Integer
Dim c As Integer
Dim r As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("MV").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "LMMV"
For Col = 2 To lc
For Row = 3 To lr
y = Sheets("N").Cells(Row, 1).Value
n1 = Sheets("MV").Cells(y, Col).Value
Next Row
Next Col
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Dim lr As Integer
Dim lc As Integer
Dim i As Integer
Dim j As Integer
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lr = Sheets("Ret").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("Ret").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "MRC"
Sheets("LESDE").Activate
For i = 2 To lc
For j = 2 To lr
Else
End If
Next j
Next i
Sheets("MRC").Columns.AutoFit
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Sub fama()
Dim lr As Long, lc As Long, r As Integer, c As Integer
Application.ScreenUpdating = False
lr = Sheets("MRC").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("MRC").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "FF3"
For r = 2 To lr - 2
P1 = Application.WorksheetFunction.Percentile(n, 0.5)
P2 = Application.WorksheetFunction.Percentile(m, 0.3)
P3 = Application.WorksheetFunction.Percentile(m, 0.7)
Next r
End Sub
Sub Amihud12()
Application.ScreenUpdating = False
lr = Sheets("N").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("DAMI").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "Amihud"
For i = 1 To 12
Sheets.Add after:=Sheets(Sheets.Count)
For Col = 2 To lc
x=0
y=0
For Row = 2 To lr
Sum = Application.WorksheetFunction.Sum(n)
Count = Application.WorksheetFunction.Count(n)
If Count >= 5 Then ' traded more than 5 days in any month
Else
End If
End If
Next Row
Next Col
Next
Application.ScreenUpdating = True
End Sub
Sub MPBM()
Application.ScreenUpdating = False
lr = Sheets("AmihudM12").Cells(Rows.Count, 1).End(xlUp).Row
lc = Sheets("AmihudM12").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = "Ami12ret"
x=2
For r = 14 To lr
P1 = Application.WorksheetFunction.Percentile(n, 0.25)
P2 = Application.WorksheetFunction.Percentile(n, 0.5)
P3 = Application.WorksheetFunction.Percentile(n, 0.75)
Sheets("Ami12ret").Cells(x, 2).Value = Application.WorksheetFunction.AverageIfs(m, n, "<=" & P1)
x=x+1
Next r
End Sub