SlideShare a Scribd company logo
1 of 2
SubDurbin_Watson()
Dim UserXRange AsRange
Dim UserYRange AsRange
Dim s AsDouble
Dim j AsInteger
On Error GoTo Canceled
Set UserXRange = Application.InputBox(Prompt:="Please SelectXRange",Title:="Range XSelect",
Type:=8)
Set UserYRange = Application.InputBox(Prompt:="PleaseSelectYRange",Title:="Range YSelect",
Type:=8)
Range("J1:L5").Value =Application.WorksheetFunction.LinEst(UserYRange,UserXRange,True,True)
j = 1
s = 0
Do While Cells(j,3) <> Empty
Cells(j,4).Value=Cells(j,3).Value - (Cells(j,1).Value*Cells(1,11).Value +Cells(j,2).Value*Cells(1,
10).Value + Cells(1,12).Value)
j = j + 1
Loop
j = 2
Do While Cells(j,4) <> Empty
s = s + (Cells(j,4).Value - Cells(j - 1,4).Value) *(Cells(j,4).Value- Cells(j - 1,4).Value)
j = j + 1
Loop
v = s / Cells(5,11).Value
Columns(4).Delete
j = 1
Do While j <= 3
Columns(9).Delete
j = j + 1
Loop
MsgBox ("Durbin-WatsonStatisticis:"& v)
ExitSub
Canceled:
ActiveWindow.Close
ActiveWindow.Close
ActiveWorkbook.RunAutoMacrosWhich:=xlAutoClose
End Sub
Thiscode isVBA Excel code for computingthe Durbin-WatsonStatisticusedtodetermine
autocorrelationamongindependentvariables.Thiscode isonly fortwoindependentvariablesandone
dependentvariable.

More Related Content

Similar to DurbinWatsonVBA

Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...scalaconfjp
 
0.0. secante modificada
0.0. secante modificada0.0. secante modificada
0.0. secante modificadaAgua SAC
 
0.0. steffensen.naol
0.0. steffensen.naol0.0. steffensen.naol
0.0. steffensen.naolAgua SAC
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
0.0. biseccion
0.0. biseccion0.0. biseccion
0.0. biseccionAgua SAC
 
Futzing with actors (etc.)
Futzing with actors (etc.)Futzing with actors (etc.)
Futzing with actors (etc.)league
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)Pedro Rodrigues
 
Beyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheckBeyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheckFranklin Chen
 
0.0. falsa posicion-naol
0.0. falsa posicion-naol0.0. falsa posicion-naol
0.0. falsa posicion-naolAgua SAC
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyondFrancis Johny
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOJorge Vásquez
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfTimothy McBush Hiele
 

Similar to DurbinWatsonVBA (20)

Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
Functional Object-Oriented Imperative Scala / 関数型オブジェクト指向命令型 Scala by Sébasti...
 
0.0. secante modificada
0.0. secante modificada0.0. secante modificada
0.0. secante modificada
 
0.0. steffensen.naol
0.0. steffensen.naol0.0. steffensen.naol
0.0. steffensen.naol
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
Into Clojure
Into ClojureInto Clojure
Into Clojure
 
Meet scala
Meet scalaMeet scala
Meet scala
 
0.0. biseccion
0.0. biseccion0.0. biseccion
0.0. biseccion
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Futzing with actors (etc.)
Futzing with actors (etc.)Futzing with actors (etc.)
Futzing with actors (etc.)
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 
Beyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheckBeyond xUnit example-based testing: property-based testing with ScalaCheck
Beyond xUnit example-based testing: property-based testing with ScalaCheck
 
0.0. falsa posicion-naol
0.0. falsa posicion-naol0.0. falsa posicion-naol
0.0. falsa posicion-naol
 
bobok
bobokbobok
bobok
 
ECMAScript 6 and beyond
ECMAScript 6 and beyondECMAScript 6 and beyond
ECMAScript 6 and beyond
 
A Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIOA Prelude of Purity: Scaling Back ZIO
A Prelude of Purity: Scaling Back ZIO
 
Scala
ScalaScala
Scala
 
R Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdfR Cheat Sheet for Data Analysts and Statisticians.pdf
R Cheat Sheet for Data Analysts and Statisticians.pdf
 
Arrays
ArraysArrays
Arrays
 

DurbinWatsonVBA

  • 1. SubDurbin_Watson() Dim UserXRange AsRange Dim UserYRange AsRange Dim s AsDouble Dim j AsInteger On Error GoTo Canceled Set UserXRange = Application.InputBox(Prompt:="Please SelectXRange",Title:="Range XSelect", Type:=8) Set UserYRange = Application.InputBox(Prompt:="PleaseSelectYRange",Title:="Range YSelect", Type:=8) Range("J1:L5").Value =Application.WorksheetFunction.LinEst(UserYRange,UserXRange,True,True) j = 1 s = 0 Do While Cells(j,3) <> Empty Cells(j,4).Value=Cells(j,3).Value - (Cells(j,1).Value*Cells(1,11).Value +Cells(j,2).Value*Cells(1, 10).Value + Cells(1,12).Value) j = j + 1 Loop j = 2 Do While Cells(j,4) <> Empty s = s + (Cells(j,4).Value - Cells(j - 1,4).Value) *(Cells(j,4).Value- Cells(j - 1,4).Value) j = j + 1 Loop v = s / Cells(5,11).Value Columns(4).Delete j = 1 Do While j <= 3 Columns(9).Delete j = j + 1 Loop MsgBox ("Durbin-WatsonStatisticis:"& v) ExitSub
  • 2. Canceled: ActiveWindow.Close ActiveWindow.Close ActiveWorkbook.RunAutoMacrosWhich:=xlAutoClose End Sub Thiscode isVBA Excel code for computingthe Durbin-WatsonStatisticusedtodetermine autocorrelationamongindependentvariables.Thiscode isonly fortwoindependentvariablesandone dependentvariable.