(************** Content-type: application/mathematica ************** Mathematica-Compatible Notebook This notebook can be used with any Mathematica-compatible application, such as Mathematica, MathReader or Publicon. The data for the notebook starts with the line containing stars above. To get the notebook into a Mathematica-compatible application, do one of the following: * Save the data starting with the line of stars above into a file with a name ending in .nb, then open the file inside the application; * Copy the data starting with the line of stars above to the clipboard, then use the Paste menu command inside the application. Data for notebooks contains only printable 7-bit ASCII and can be sent directly in email or through ftp in text mode. Newlines can be CR, LF or CRLF (Unix, Macintosh or MS-DOS style). NOTE: If you modify the data for this notebook not in a Mathematica- compatible application, you must delete the line below containing the word CacheID, otherwise Mathematica-compatible applications may try to use invalid cache data. For more information on notebooks and Mathematica-compatible applications, contact Wolfram Research: web: http://www.wolfram.com email: info@wolfram.com phone: +1-217-398-0700 (U.S.) Notebook reader applications are available free of charge from Wolfram Research. *******************************************************************) (*CacheID: 232*) (*NotebookFileLineBreakTest NotebookFileLineBreakTest*) (*NotebookOptionsPosition[ 18079, 391]*) (*NotebookOutlinePosition[ 18722, 413]*) (* CellTagsIndexPosition[ 18678, 409]*) (*WindowFrame->Normal*) Notebook[{ Cell[CellGroupData[{ Cell["Preliminary Trials", "Subtitle"], Cell[BoxData[{ \(\(eqn1\ = \ Log[a]\ + \ Log[b]\ + \ Log[c]\ + \ Log[d]\ - \ Log[e]\ - \ Log[f]\ - \ Log[g]\ - \ Log[h] \[Equal] 0;\)\), "\[IndentingNewLine]", \(\(eqn2\ = \ Log[a]\ + \ Log[f]\ - \ Log[b]\ - \ Log[e]\ \[Equal] \ Log[2]/4;\)\), "\[IndentingNewLine]", \(\(eqn3 = \ \ Log[c]\ + \ Log[h]\ - \ Log[d]\ - \ Log[g] \[Equal] Log[2]/4;\)\), "\[IndentingNewLine]", \(\(eqn4\ = \ Log[a]\ + \ Log[g]\ - \ Log[c]\ - \ Log[e]\ \[Equal] \ Log[2]/4;\)\), "\[IndentingNewLine]", \(\(eqn5\ = \ Log[b]\ + \ Log[h]\ - \ Log[f]\ - \ Log[d]\ \[Equal] \ Log[2]/4;\)\)}], "Input"], Cell[BoxData[{ \(\(const1 = \ a\ + \ e \[Equal] 147;\)\), "\[IndentingNewLine]", \(\(const2\ = \ b + \ f\ \[Equal] 9;\)\), "\[IndentingNewLine]", \(\(const3 = \ c\ + \ g\ \[Equal] 123;\)\), "\[IndentingNewLine]", \(\(const4\ = \ d\ + \ h\ \[Equal] 33;\)\)}], "Input"], Cell[CellGroupData[{ Cell[BoxData[ \(Timing[ Solve[{\ eqn1, eqn2, \ eqn3, \ eqn4, \ const1, \ const2, \ const3, \ const4}]]\)], "Input"], Cell[BoxData[ \({93.75999999999999`\ Second, {{f \[Rule] 9\/2, a \[Rule] 147\ \((2 - 2\^\(1/4\) + \@2 - 2\^\(3/4\))\), h \[Rule] 33\ \((2 - 2\^\(1/4\) + \@2 - 2\^\(3/4\))\), b \[Rule] 9\/2, d \[Rule] 33\ \((\(-1\) + 2\^\(1/4\) - \@2 + 2\^\(3/4\))\), c \[Rule] 123\/2, g \[Rule] 123\/2, e \[Rule] 147\ \((\(-1\) + 2\^\(1/4\) - \@2 + 2\^\(3/4\))\)}}}\)], "Output"] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[{ \(\(t = Solve[{\ eqn1, eqn2, \ eqn3, \ eqn4, \ const1, \ const2, \ const3, \ const4}];\)\), "\[IndentingNewLine]", \(Map[N, {\ a, \ b, \ c, \ d, \ e, \ f, \ g, \ h}\ /. \ t]\)}], "Input"], Cell[BoxData[ \({{79.85240167885287`, 4.5`, 61.5`, 15.073950643522826`, 67.14759832114713`, 4.5`, 61.5`, 17.926049356477176`}}\)], "Output"] }, Open ]], Cell[BoxData[ \(\(\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\(\[IndentingNewLine]\)\ \)\)], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["Sensitivity Analysis", "Subtitle"], Cell["\<\ 1. Set up general log-linear equations 2. Fill in parameter constraints from the observed data 3.Open list to hold results 4. Do[ ] the calculation 5. Process the result for input into Stata 6. Save results. WARNING: For some reason it takes much longer to obtain results if delta and \ gamma are whole numbers other than 1, but not for other numbers (a few \ minutes vs less than a second). NOTE: The stuff below implements one particular analysis. The file can \ easily be adapted for other analyses by replacing the cellsize constraints in \ {const1, ..., const4}, and by changing the range and pattern of delta/gamma \ combinations in the last two { } constructs of the Do[ ] loop. (Example: \ {del, 3, 6, .1} means that delta is evaluated over the range 3-6 in .1 \ intervalls.)\ \>", "Text"], Cell[BoxData[{ \(\(eqn1\ = \ Log[a]\ + \ Log[b]\ + \ Log[c]\ + \ Log[d]\ - \ Log[e]\ - \ Log[f]\ - \ Log[g]\ - \ Log[h] \[Equal] 0;\)\), "\n", \(\(eqn2\ = \ Log[a]\ + \ Log[f]\ - \ Log[b]\ - \ Log[e]\ \[Equal] \ Log[del];\)\), "\n", \(\(eqn3 = \ \ Log[c]\ + \ Log[h]\ - \ Log[d]\ - \ Log[g] \[Equal] Log[del];\)\), "\n", \(\(eqn4\ = \ Log[a]\ + \ Log[g]\ - \ Log[c]\ - \ Log[e]\ \[Equal] \ Log[gam];\)\), "\n", \(\(\(eqn5\ = \ Log[b]\ + \ Log[h]\ - \ Log[f]\ - \ Log[d]\ \[Equal] \ Log[gam];\)\(\n\) \)\), "\[IndentingNewLine]", \(\(const1\ = \ a\ + \ e\ \[Equal] 450;\)\), "\n", \(\(const2\ = \ b + \ f\ \[Equal] \ 50;\)\), "\n", \(\(const3\ = \ c\ + \ g\ \[Equal] \ 400;\)\), "\n", \(\(\(const4\ = \ d\ + \ h\ \[Equal] \ \ 100;\)\(\[IndentingNewLine]\) \)\), "\[IndentingNewLine]", \(\(\(s = {};\)\(\[IndentingNewLine]\) \)\), "\[IndentingNewLine]", \(\(Do[ q = Solve[{\ eqn1, eqn2, \ eqn3, \ eqn4, \ const1, \ const2, \ const3, \ const4}]; r = Flatten[Map[N, {\ a, e, b, f, c, g, d, h}\ /. \ q], 1]; s = \ Append[s, r], \[IndentingNewLine]{del, 1.000001, \ 5.000001, \ 1}, \ {gam, \ 1.000001, 5.000001, \ 1}];\)\[IndentingNewLine]\), "\[IndentingNewLine]", \(\(results = Transpose[s];\)\[IndentingNewLine]\), "\[IndentingNewLine]", \(\(Export["\", results, \ "\"];\)\)}], "Input"], Cell[TextData[{ "\nNote: \"Results.dat\" is a matrix of estimates for parameters \ {a,b,...,h} where each row-vector gives the results for one parameter across \ the specified range of (delta, gamma) combinations. Specifically:\n\n", StyleBox["Rows", FontWeight->"Bold"], "\n\tD R U Parameter ", StyleBox["Row", FontWeight->"Bold"], "\n\t0 0 0\ta\t1\n\t0 0 1\te\t2\n\t0 1 0\tb\t3\n\t0 1 1\tf\t\ 4\n\t1 0 0\tc\t5\n\t1 0 1\tg\t6\n\t1 1 0\td\t7\n\t1 1 1\th\t8\ \n\n", StyleBox["Columns ", FontWeight->"Bold"], "are vectors of parameters for particular combination of (delta, gamma). \ Specifically\n\t\n\t", StyleBox["Columns ", FontWeight->"Bold"], "delta\tgamma", "\n\t1-6\t\t1\t1-2 in intervalls of 0.2\n\t7-12\t\t1.2\t1-2 in intervalls \ of 0.2\n\t13-18\t\t1.4\t \" \"\n\t...\t\t...\t\" \"\n\t31-36\t\t2\t\" \"\n\t\n\ \"Results.dat\" can be read into Stata and should be used as iweight in the \ logit analysis.\n", StyleBox["Stata command: ", FontWeight->"Bold"], "infile var1-var36 using \"C:\\Program Files\\Wolfram \ Research\\Mathematica\\4.0\\Results.dat\"" }], "Text"], Cell[BoxData[""], "Input"], Cell["This is how the results will read into Stata:", "Text"], Cell[CellGroupData[{ Cell[BoxData[ \(MatrixForm[results]\)], "Input"], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"73.5`", "74.33750340238774`", "75.0454415247549`", "75.6584583601443`", "76.19893095763685`", "76.6821543862051`", "74.33750340238774`", "75.17478935514508`", "75.88237413965365`", "76.4949595806608`", "77.03495529385911`", "77.51767576858711`", "75.0454415247549`", "75.88237413965365`", "76.58951714265186`", "77.20161421910649`", "77.74109795990094`", "78.2232961499045`", "75.6584583601443`", "76.4949595806608`", "77.20161421910649`", "77.81319698560125`", "78.35215698190359`", "78.83383118789848`", "76.19893095763685`", "77.03495529385911`", "77.74109795990094`", "78.35215698190359`", "78.89059340435587`", "79.37175052405604`", "76.6821543862051`", "77.51767576858711`", "78.2232961499045`", "78.83383118789848`", "79.37175052405604`", "79.8524016788529`"}, {"73.5`", "72.66249659761226`", "71.9545584752451`", "71.3415416398557`", "70.80106904236315`", "70.3178456137949`", "72.66249659761226`", "71.82521064485492`", "71.11762586034635`", "70.5050404193392`", "69.96504470614089`", "69.48232423141289`", "71.9545584752451`", "71.11762586034635`", "70.41048285734814`", "69.79838578089351`", "69.25890204009906`", "68.7767038500955`", "71.3415416398557`", "70.5050404193392`", "69.79838578089351`", "69.18680301439875`", "68.64784301809641`", "68.16616881210152`", "70.80106904236315`", "69.96504470614089`", "69.25890204009906`", "68.64784301809641`", "68.10940659564413`", "67.62824947594396`", "70.3178456137949`", "69.48232423141289`", "68.7767038500955`", "68.16616881210152`", "67.62824947594396`", "67.1475983211471`"}, {"4.5`", "4.551275718513534`", "4.594618868862546`", "4.632150511845569`", "4.6652406708757255`", "4.694825778747251`", "4.448724281486466`", "4.5`", "4.543353537322365`", "4.58090186494359`", "4.614012656575896`", "4.643620912023972`", "4.405381131137454`", "4.456646462677635`", "4.5`", "4.537554832270288`", "4.570676370751696`", "4.600298214419211`", "4.367849488154431`", "4.41909813505641`", "4.462445167729712`", "4.5`", "4.533125880407923`", "4.5627550551551215`", "4.3347593291242745`", "4.385987343424104`", "4.429323629248304`", "4.466874119592077`", "4.5`", "4.529632216719526`", "4.305174221252749`", "4.356379087976028`", "4.399701785580789`", "4.4372449448448785`", "4.470367783280474`", "4.5`"}, {"4.5`", "4.448724281486466`", "4.405381131137454`", "4.367849488154431`", "4.3347593291242745`", "4.305174221252749`", "4.551275718513534`", "4.5`", "4.456646462677635`", "4.41909813505641`", "4.385987343424104`", "4.356379087976028`", "4.594618868862546`", "4.543353537322365`", "4.5`", "4.462445167729712`", "4.429323629248304`", "4.399701785580789`", "4.632150511845569`", "4.58090186494359`", "4.537554832270288`", "4.5`", "4.466874119592077`", "4.4372449448448785`", "4.6652406708757255`", "4.614012656575896`", "4.570676370751696`", "4.533125880407923`", "4.5`", "4.470367783280474`", "4.694825778747251`", "4.643620912023972`", "4.600298214419211`", "4.5627550551551215`", "4.529632216719526`", "4.5`"}, {"61.5`", "60.79923184698169`", "60.20687545887854`", "59.693943004777225`", "59.24171083136509`", "58.837381023787565`", "62.20076815301831`", "61.5`", "60.90750165659435`", "60.39434117910426`", "59.9418270267961`", "59.53718086900571`", "62.79312454112146`", "62.09249834340565`", "61.5`", "60.98675062563939`", "60.534089599726826`", "60.12925773627079`", "63.306056995222775`", "62.60565882089574`", "62.01324937436061`", "61.5`", "61.04727963442505`", "60.642347579546666`", "63.75828916863491`", "63.0581729732039`", "62.465910400273174`", "61.95272036557495`", "61.5`", "61.095026371499806`", "64.16261897621243`", "63.46281913099429`", "62.87074226372921`", "62.357652420453334`", "61.904973628500194`", "61.5`"}, {"61.5`", "62.20076815301831`", "62.79312454112146`", "63.306056995222775`", "63.75828916863491`", "64.16261897621243`", "60.79923184698169`", "61.5`", "62.09249834340565`", "62.60565882089574`", "63.0581729732039`", "63.46281913099429`", "60.20687545887854`", "60.90750165659435`", "61.5`", "62.01324937436061`", "62.465910400273174`", "62.87074226372921`", "59.693943004777225`", "60.39434117910426`", "60.98675062563939`", "61.5`", "61.95272036557495`", "62.357652420453334`", "59.24171083136509`", "59.9418270267961`", "60.534089599726826`", "61.04727963442505`", "61.5`", "61.904973628500194`", "58.837381023787565`", "59.53718086900571`", "60.12925773627079`", "60.642347579546666`", "61.095026371499806`", "61.5`"}, {"16.5`", "16.31198903211704`", "16.153064147504`", "16.015448123232915`", "15.894117540122341`", "15.785638811260078`", "16.31198903211704`", "16.12402687945723`", "15.965181315587957`", "15.827662134953696`", "15.706438607501015`", "15.598072786643709`", "16.153064147504`", "15.965181315587957`", "15.806434927159788`", "15.669025379384257`", "15.547916784512033`", "15.439668211245928`", "16.015448123232915`", "15.827662134953696`", "15.669025379384257`", "15.531731288946657`", "15.410740269368581`", "15.302609325165646`", "15.894117540122341`", "15.706438607501015`", "15.547916784512033`", "15.410740269368581`", "15.289866786777253`", "15.181851923171095`", "15.785638811260078`", "15.598072786643709`", "15.439668211245928`", "15.302609325165646`", "15.181851923171095`", "15.073950643522819`"}, {"16.5`", "16.68801096788296`", "16.846935852496`", "16.984551876767085`", "17.10588245987766`", "17.21436118873992`", "16.68801096788296`", "16.87597312054277`", "17.034818684412045`", "17.172337865046302`", "17.293561392498987`", "17.40192721335629`", "16.846935852496`", "17.034818684412045`", "17.19356507284021`", "17.33097462061574`", "17.452083215487967`", "17.56033178875407`", "16.984551876767085`", "17.172337865046302`", "17.33097462061574`", "17.468268711053344`", "17.58925973063142`", "17.697390674834352`", "17.10588245987766`", "17.293561392498987`", "17.452083215487967`", "17.58925973063142`", "17.710133213222747`", "17.818148076828905`", "17.21436118873992`", "17.40192721335629`", "17.56033178875407`", "17.697390674834352`", "17.818148076828905`", "17.92604935647718`"} }], "\[NoBreak]", ")"}], (MatrixForm[ #]&)]], "Output"] }, Open ]], Cell[BoxData[""], "Input"], Cell["\<\ If everything went right, the following should give a matrix with rows equal \ to the constraints put into the analysis. \ \>", "Text"], Cell[CellGroupData[{ Cell[BoxData[{ \(\(t = results;\)\), "\[IndentingNewLine]", \(\(v = {t[\([1]\)] + t[\([2]\)], \ t[\([3]\)] + t[\([4]\)], \ t[\([5]\)] + t[\([6]\)], t[\([7]\)] + t[\([8]\)]};\)\), "\[IndentingNewLine]", \(MatrixForm[v]\)}], "Input"], Cell[BoxData[ TagBox[ RowBox[{"(", "\[NoBreak]", GridBox[{ {"147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`", "147.`"}, {"9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`", "9.`"}, {"123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`", "123.`"}, {"33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`", "33.`"} }], "\[NoBreak]", ")"}], Function[ BoxForm`e$, MatrixForm[ BoxForm`e$]]]], "Output"] }, Open ]], Cell["\<\ Written by Felix Elwert (elwert@wjh.harvard.edu) and David Harding \ (dharding@wjh.harvard.edu). \ \>", "Text"] }, Open ]] }, FrontEndVersion->"4.1 for Microsoft Windows", ScreenRectangle->{{0, 1024}, {0, 695}}, WindowSize->{715, 500}, WindowMargins->{{0, Automatic}, {Automatic, 0}} ] (******************************************************************* Cached data follows. If you edit this Notebook file directly, not using Mathematica, you must remove the line containing CacheID at the top of the file. The cache data will then be recreated when you save this file from within Mathematica. *******************************************************************) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[1727, 52, 38, 0, 64, "Subtitle"], Cell[1768, 54, 727, 15, 110, "Input"], Cell[2498, 71, 294, 4, 90, "Input"], Cell[CellGroupData[{ Cell[2817, 79, 136, 3, 30, "Input"], Cell[2956, 84, 445, 8, 76, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3438, 97, 234, 4, 50, "Input"], Cell[3675, 103, 153, 2, 29, "Output"] }, Open ]], Cell[3843, 108, 108, 2, 90, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[3988, 115, 40, 0, 53, "Subtitle"], Cell[4031, 117, 818, 18, 261, "Text"], Cell[4852, 137, 1601, 33, 410, "Input"], Cell[6456, 172, 1164, 27, 508, "Text"], Cell[7623, 201, 26, 0, 30, "Input"], Cell[7652, 203, 61, 0, 33, "Text"], Cell[CellGroupData[{ Cell[7738, 207, 52, 1, 30, "Input"], Cell[7793, 210, 7972, 127, 137, "Output"] }, Open ]], Cell[15780, 340, 26, 0, 30, "Input"], Cell[15809, 342, 145, 3, 33, "Text"], Cell[CellGroupData[{ Cell[15979, 349, 267, 5, 70, "Input"], Cell[16249, 356, 1678, 26, 73, "Output"] }, Open ]], Cell[17942, 385, 121, 3, 33, "Text"] }, Open ]] } ] *) (******************************************************************* End of Mathematica Notebook file. *******************************************************************)