Click here to load reader

《 实验经济学 》 第七讲: 经济实验程序开发方法

Embed Size (px)

DESCRIPTION

《 实验经济学 》 第七讲: 经济实验程序开发方法. 杜宁华 上海财经大学经济学院,经济学实验室 2009 年 4 月. 确保实验结果的有效性,实验室实验通常两小时内结束 人力组织 十几个甚至二十几个交易回合 每个交易回合随机配对 怎么办? 开发计算机程序. 起先,开发实验程序只是为了更充分地掌握数据、减少实验运行失误 近年的发展表明,实验运行(交易)过程的电子化为实验方法开辟了新的天地 大大降低了交易成本 拓展了市场参与者的市场语言 新市场机制在互联网和电子商务时代随处可见 - PowerPoint PPT Presentation

Citation preview

  • 2009 4

  • 1Visual Basic

  • VB

  • VB

  • Microsoft Visual Basic 6.0

    EXE

  • Form1

    FormVB

  • VBVBVB

    VB

  • VB

  • Form1frmHello

    111Hello

    frmHelloHello

  • VB

    FormfrmLabellblTextBoxtxtCommandButtoncmd

    txtInput

  • frmHello

    frmHelloCaptionHello

    ImagefrmHelloImage1

    Image1Picture

    Image1Image1

  • Image1Image1imgNinghuaVisibleFalse

    VB

  • labelfrmHelloLabel1

    Label1lblHelloimgNinghua

    lblHelloCaptionHello, everyone.lblHelloFontlblHello

  • lblHello

    Private Sub lblHello_Click()

    End Sub

  • lblHello_Click

    VBVB

    lblHello_ClicklblHello

    Private Sub lblHello_Click()End SublblHelloVB

  • Private Sub lblHello_Click()

    imgNinghua.Visible = True

    End Sub

  • Hello, everyone.

  • VB

    Hello.exe(K),Hello.exe

  • 1VB

  • VB

  • Balloon.Color = Red Balloon.Diameter = 10 Balloon.Inflated = True

    (Balloon) (Color) (Red)

  • Balloon.Inflate Balloon.Deflate Balloon.Rise 5

  • Sub Balloon_Puncture() Balloon.Deflate Balloon.MakeNoise "Bang" Balloon.Inflated = False Balloon.Diameter = 1

    End Sub

  • 2

  • CFortran

    JavaVB

  • Label

    TextBox

  • TextBox

  • TaskObjectEventTOE

  • TaskObjectEventtxtPriceoptRevoptRev_Click optNRevoptRev_Click cmdOKcmdOK_Click

  • VBoptRevoptNRev

  • Programming with Visual Basic 6.0 Enhanced Edition, Diane Zak, Tutorial 2

  • 1.

  • Byte 0255Boolean True or FalseCurrency 154+/- 9E14Date 1001199991231Double +/- 5E-3241.8E308Integer -3276832767Long +/- 2000000000Object VBSingle +/- 1E-453E38String 65400Variant

  • BytebytBooleanblnCurrencycurDate(time)dtmDoubledblIntegerintLonglngObjectobjSinglesngStringstrVariantvnt

  • 255VBVBVBPrint

  • Dim variablename As datatype

    Public variablename As datatypeintRoundDim intRound As Integer

  • =Label1.Caption = Hello!intRound = 10curPrice = 10.23

  • intRound = 10intRound = intRound +5

    VB0

  • DimPrivate Sub lblHello_Click()Dim i As IntegerEnd Sub

    ilblHello_Click()

  • Dim

    General Declaration

  • Public Module1

  • Option Explicit

  • VB

    Option Explicit

    Option Explicit

  • Option ExplicitDim i, j, k As IntegerDim strName As String

  • 2.

  • Dim arrayname(lower subscript To upper subscript, lower subscript To upper subscript) As datatype Public arrayname(lower subscript To upper subscript,lower subscript To upper subscript) As datatype

  • arrayname

    lower subscript To upper subscript

    VB60

    Option Explicit

  • 10curPriceDim curPrice(1 To 10, 1 To 3) As Currency

    curPrice

  • 3.

  • Public Const constname As datatype = expression

    VB

  • Programming with Visual Basic 6.0 Enhanced Edition, Diane Zak, Tutorial 3

  • 10X1 X

  • 1IfThenElse

  • IfThenElseVB

    If condition Then[instructions when the condition is true][Else[instructions when the condition is false]]End If

  • conditionTrue or False

    ThenElse

    End If

    IfThenElseElse ElseEnd If

  • VB

    VB

  • VB6=>>=
  • 110 + 3 < 5 * 25 * 21010 + 31313 < 10False

    27 > 3 * 4 / 23 * 41212 / 267 > 6True

  • UCaseLCase

  • VBVB

  • UCaseUCase(String)String

    UCase(String)String

    UCaseUCase

  • LCaseLCase(String)

  • NotAndOrVB

    NotAndOr

    Not

    And

    Or

  • 13 > 2 And 6 > 53 > 2True6 > 5TrueTrue And True

    210 < 25 And 6 > 5 + 15 + 1610 < 25True6 > 6FalseTrue And False

  • 38 = 4 * 2 Or 6 > 5 + 14 * 288 = 8TrueOr3

  • AndAndVBAnd

    OrOrVBOr

  • 2IfThenElse

  • 1sngCostintSellerID131.221.51.8sngCost

  • If intSellerID = 1 Or intSellerID = 3 ThensngCost = 1.2ElseIf intSellerID = 2 ThensngCost = 1.5ElsesngCost = 1.8End IfEnd If

  • 2

    11000050010000200

    22000060020000550

    150

    intSellerIDsngSalessngBonus

  • If intSellerID = 1 ThenIf sngSales >= 10000 thensngBonus = 500ElsesngBonus = 200End IfElseIf intSellerID = 2 ThenIf sngSales >= 20000 ThensngBonus = 600ElsesngBonus = 550End IfElsesngBonus = 150End IfEnd If

  • If intSellerID = 1 And sngSales >= 10000 ThensngBonus = 500ElseIf intSellerID = 1 And sngSales < 10000 ThensngBonus = 200ElseIf intSellerID = 2 And sngSales >= 20000 ThensngBonus = 600ElseIf intSellerID = 2 And sngSales < 20000 ThensngBonus = 550ElsesngBonus = 150End IfEnd IfEnd IfEnd If

  • 3Case

  • Case

    IfThenElseCase

  • Select Case testexpression[Case expressionlist1[instructions for the first case]][Case expressionlist2[instructions for the second case]][Case expressionlistn[instructions for the nth case]][Case Else [instructions for when the testexpression does not match any of the expressionlists]]End Select

  • testexpression

    expressionlistCase

    CaseEnd Select

    Case ElseCaseCase ElseCaseEnd Select

  • a testexpression bCase

    Select Case testexpression[Case a To b[instructions for the case of a to b]]End Select

  • a testexpressionCase

    Select Case testexpression[Case Is >=a [instructions for the case of >=a]]End Select

  • 1Select Case intSellerIDCase 1, 3sngCost = 1.2Case 2sngCost = 1.5Case ElsesngCost = 1.8End Select

  • 2Select Case intSellerIDCase 1Select Case sngSalesCase Is >= 10000sngBonus = 500Case ElsesngBonus = 200End SelectCase 2Select Case sngSalesCase Is >= 20000sngBonus = 600Case ElsesngBonus = 550End SelectCase ElsesngBonus = 150End Select

  • 2Select Case TrueCase intSellerID = 1 And sngSales >= 10000sngBonus = 500Case intSellerID = 1 And sngSales < 10000sngBonus = 200Case intSellerID = 2 And sngSales >= 20000sngBonus = 600Case intSellerID = 2 And sngSales < 20000sngBonus = 550Case ElsesngBonus = 150End Select

  • Programming with Visual Basic 6.0 Enhanced Edition, Diane Zak, Tutorial 4

  • For NextDo WhileDo Until

  • 1For Next

  • For NextFor counter = startvalue to endvalue [Step stepvalue][instructions]Next counter

  • Counter

    startvalueendvaluestepvalue

    VB1

  • For Next

    startvalueCounter

  • stepvalueCounterendvaluestepvalueCounterendvalue

    instructions

  • stepvalueCounter

    CounterendvalueCounterendvalue

  • For Next

    12150sngTPayoff1 to 1212sngTPayoff(i)i150

  • Dim i As IntegerDim sngTPayoff(1 To 12) As SingleFor i = 1 to 12sngTPayoff(i) = 150Next i

  • 2Do WhileDo Until

  • Do While

    Do Until

    Do WhileDo UntilFor Next

  • Do While

    Do While condition[loop instructions]Loop

    Do Until

    Do [loop instructions]Loop Until condition

  • conditioncondition

    Do Whileconditionloop instructions

    Do Untilconditionloop instructionscondtion

  • Do WhileFor Next

    Do UntilDo Until

  • Do WhileDim i As IntegerDim sngTPayoff(1 To 12) As Singlei = 1Do While i
  • Do UntilDim i as IntegerDim sngTPayoff(1 To 12) As Singlei = 1Do sngTPayoff(i) = 150i = i + 1Loop Until i > 12

  • 3

  • 5

  • 01

  • 1220ABstrChoice(1 to 12, 1 to 20)strChoice(i, j)ijintChoiceA(1 to 20)A

  • Dim i, j As IntegerDim intChoiceA(1 To 20) As Integer

    For i = 1 to 20intChoiceA(i) = 0For j = 1 to 12If strChoice(j, i) = A ThenintChoiceA(i) = intChoiceA(i) + 1End IfNext jNext i

  • 1220sngPayoff(1 to 12, 1 to 20)sngPayoff(i, j)ijsngTPayoff(1 to 12)sngTPayoff(i) i150

  • Dim i, j As IntegerDim sngTPayoff(1 To 12) As Single

    For i = 1 to 12sngTPayoff(i) = 150For j = 1 to 20sngTPayoff(i) = sngTPayoff(i)+ sngPayoff(i, j) Next jNext i

  • 1

  • VB

  • 2

  • VB*.txt

    Microsoft Excel

  • OpenOpen pathname For mode As # filenumber

  • pathname

    pathname

  • mode

    InputVB

    OutputVB

    AppendVB

  • filenumber

    filenumber15111511VB511

  • VB

  • D:\Experiment\Result.txt

    Open "D:\Experiment\Result.txt" For Output As #1

  • CloseClose [# filenumber]

    filenumber

    CloseVB

  • Result.txtClose # 1

  • InputInput # filenumber, variablelist

  • filenumber

    variablelist

  • 1055D:\Experiment\Matching.txt10Matching.txt

    11029384756

  • 5

    Proposer(1 to 5)Responder(1 to 5)

  • Dim i As IntegerDim Proposer(1 To 5) As Integer, Responder(1 To 5) As IntegerOpen "D:\Experiment\Matching.txt" For Input As #1For i=1 to 5Input #1, Proposer(i), Responder(i)Next iClose #1

  • WriteWrite # filenumber, [outputlist]

  • filenumber

    outputlistInput

  • 1010D:\Experiment\Result.txt

    Role(i)iGroup(i)iFChoice(i) iSChoice(i) iPayoff(i)i

  • Open "D:\Experiment\result.txt" For Output As #1Write #1, "ID", "Role", "Group", "First Movers Choice", "Second Movers Choice", "Payoff" For i = 1 to 10Write #1, i, Role(i), Group(i), FChoice(i), SChoice(i), Payoff(i)Next iClose #1

  • 3EOF

  • EOFVB

    EOFEnd of FileEOFEOF(filenumber)

  • filenumber

    EOFfilenumberEOFEOF

  • EOFDo While Not EOF(1)[loop instructions]LoopDo [loop instructions]Loop Until EOF(1)

  • ESL Network Queue

  • ESL Network QueueVB

  • 1

  • n

    PC1PCn

  • 2ESL Network Queue

  • VB

  • ESL Network Queue

    ESL Network QueueVBNQmonitorNQsubject

    NQmonitorNQsubject

  • ESL Network Queue

  • NQmonitor

  • MqserverMqserverIPIPNQmonitor.mqserverNQmonitor.mqserver = ip & :2955

    ipIP

  • OpenQueues OpenQueuesNQmonitor.mqserverNQmonitor

    NQmonitor. OpenQueues

  • SendMessage NQmonitorSendMessageSendMessageOpenQueuesConnectQueuesNQmonitor.SendMessage Message, MessageType, Subject

    MessageMessageTypeSubject

  • MessageArrivedMessageArrivedNQmonitorPrivate Sub NQmonitor_MessageArrived (Message As Variant, MessageType As String, Subject As Integer) [instructions]End Sub

    MessageMessageTypeSubjectMessageArrived

  • NQsubject

  • SubjectNumberSubjectNumber

    NQmonitorMessageArrivedSubjectSubjectNumber

    NQmonitor.SendMessageSubjectSubjectNumber

  • MqserverNQsubject.mqserverIPIP

    NQsubject.mqserver = ip & :2955 ipIP

  • ConnectQueuesNQsubjectSubjectNumbermqserverNQmonitor.OpenQueuesConnectQueuesNQsubject.ConnectQueues

  • SendMessageNQsubjectSendMessageSendMessageOpenQueuesConnectQueuesNQsubject.SendMessage Message, MessageType

    MessageMessageType

  • MessageArrivedNQsubjectMessageArrivedPrivate Sub NQsubject_MessageArrived (Message As Variant, MessageType As String) [instructions]End Sub

    MessageMessageType

  • 3ESL Network Queue

  • ChatSubChatMonChatSubChatMon

  • ChatSub

  • NQsubject

    ChatSubcmdConnect

    txtHandle

    txtMessage

    txtNewMessagecmdSend

  • NQsubjectSubjectNumber-1

    IPNQsubject.mqserver

  • txtMessage

    txtMessageScrollBars2 - Vertical

    txtMessageLockedMultiLineTrue

  • cmdConnectcmdConnect_Click

    Private Sub cmdConnect_Click() NQsubject.ConnectQueues cmdConnect.Enabled = False End Sub

  • cmdSendcmdSend_Click()

    Private Sub cmdSend_Click()NQsubject.SendMessage txtHandle.Text & ": " & txtNewMessage.Text & vbCrLf, ""

    End Sub

  • NQsubjectNQsubject_MessageArrived

    Private Sub NQsubject_MessageArrived(Message As Variant, MessageType As String)txtMessage.Text = txtMessage.Text & Message

    End Sub

  • ChatSubChatSub.exe

  • ChatMon

  • IPNQmonitor.mqserver

    txtMessagetxtMessageScrollBars2 - VerticaltxtMessageLockedMultiLineTrue

  • cmdOKcmdOK_Click()Private Sub cmdOK_Click() NQmonitor.OpenQueues cmdOK.Enabled = FalseEnd Sub

  • NQmonitorNQmonitor_MessageArrivedPrivate Sub NQmonitor_MessageArrived(Message As Variant, MessageType As String, Subject As Integer)txtMessage.Text = txtMessage.Text & MessageNQmonitor.SendMessage Message, "", -1End Sub

  • ChatMon.exe

    ChatMon.exeOK

    ChatSub.exeConnect,

  • 2 Z-tree

  • Z-tree

  • Urs FischbacherZurich Toolbox for Readymade Economic ExperimentsZtreehttp://www.iew.unizh.ch/ztree/index.php

    Ztree

  • ZtreeZleaf

    Ztree

    ZtreeZtree

  • Z-treeZtreeZleafZtree

    ZtreeZleaf

    ZtreeExcel

  • Ztree

  • 4

    20

    1.64

  • 32

    20

  • ztree.exeZtreeUntitled Treatment 1

  • ZtreeStage

    Ztreestage tree

    BackgroundGeneral Parameters

  • 201.6

    BackgroundSessionZtreeTreatmentNew Program

  • ProgramEfficiencyFactor = 1.6;Endowment = 20;

  • 20

    BackgroundZtreeTreatmentNew Stage:

  • NameContribution EntryOKContribution Entry

  • Contribution EntryActive screenWaiting screen

  • Contribution Entry

    ZtreeBox

    Contribution EntryActive screenZtreeTreatmentNew BoxStandard Box

    OK

  • Standarditem

    Contribution EntryActive screenStandardZtreeTreatmentNew Item

  • Standard

    X20X

    StandardEndowmentZtreeTreatmentNew Item

  • StandardOK

    StandardContributionZtreeTreatmentNew Button

    OK

  • Contribution EntryZtreeTreatmentNew StageProfit Display

  • Profit DisplayZtreeTreatmentNew ProgramProgram:

    SumC = sum( same( Group ), Contribution);N = count( same( Group ) );Profit = Endowment - Contribution + EfficiencyFactor * SumC/N;

  • Profit Display

    Active screenStandardContributionSumCProfitProfitLayout0.1

    StandardContinueContinueOK

  • Ztree

  • BackgroundActive screenHeaderOK

  • BackgroundWaiting screenTextPlease wait until the experiment continues

  • ZtreeFileSave AsPublic Good

  • Z-tree

  • zleaf

    zleaf

  • D:\Ztree\zLeaf.exe /name i /server 10.1.1.1

    iizleafIP10.1.1.1ztree

  • ztree.exeZtreePublic Good

    zleaf.exe

    ZtreeRunStart Treatment

    ZtreeExcelztree.exe

  • ztreezleafIPzleafztree

    zleaf1D:\Ztree\zLeaf.exe /name 12D:\Ztree\zLeaf.exe /name 2

  • ztreePublic Good

    Background211

    zleaf12ZtreeRunStart Treatment