1. Exercises for Applications
  1. Code a "package" to solve for Marshallian demand.
    1. Write a file ConsumerFOC.oxh file that declares the functions MRS(),CES(),budget(),ConsumerFOC() and the global variables that they use. (The header file should also include the standard library and import the maximize and solvenle packages.)
    2. Define the functions in ConsumerFOC.ox using the specifications above.
    3. Write a a main program to test and use the function. It would look like:
    4.     #import "ConsumerFOC"
          main() {
              // initialize the global parameters (given separately)
              // call SolveNLE()
              // print out the demand vector and the indirect utility.
              }
          
  2. Write an Ox program with:
  3. Generalize
  4. Start with this blank program.
  5. nash0.ox 
    1. Write an Ox function that:
    2. Takes arguments pay-offs of a 2 person, 2 strategy game
    3. Computes each player's best response
    4. Finds and reports fixed points in the best response function (Nash Equilibria)
    5. Generalize
      • Use labels for players and strategies to print out payoff matrices
      • Generalize to $M$ strategies
      • Generalize to $N$ players and $M_i$ strategies ($i=1,\dots,N$).
  6. Let $w\sim N(0,1)$ be a standard normal random variable. Let $EW^\star \equiv E[w | w\gt w^\star] = \int_{w^\star}^\infty w{\phi(w)\over 1-\Phi(w)}dw$ be the "truncated" mean of the random variable above the value $w^\star.$ Set $w^\star = 1.0$ (but also compute for larger and smaller values such as $w^\star=-4$ and $w^\star=5.$ Compute $EW^\star$ three different ways:
    1. Closed Form (IMR): the Inverse Mill's Ratio. Simplifying the general form to the standard normal case we get $EW^\star = {\phi(w^\star)\over 1-\Phi(w^\star)}.$ Recall that densn() and probn() are the Ox functions that return the normal density and cdf, respectively.
    2. Gaussian Quadrature (GQ): Use the QuadPack routine demonstrated in class to compute a one tail integral. So simply write a function that returns the integrand in $EW^\star$ and let the quadrature do the rest.
    3. Monte Carlo Integration (MCI): draw $R$ pseudo-random values of $w.$ Then compute the (simple) average of values that are above $w^\star.$ Recall that rann() is Ox's standard normal pseudo random number function.
    All the values should be similar, but note that the accuracy of MCI depends on $R.$ Note how the difference compared to the other approaches changes as your set $R$ to greater values. Also, note the accuracy of each approach for the larger values of $w^\star$.
  7. Once code for computing $EW^\star$ works for all the approaches, embed them in a function of the form required by Num1Derivative(). That is, re-think the calculation as $EW^\star \equiv EW(w^\star),$ the truncated mean as a function on the lower bound / reservation wage. Now you can use Num1Derivative() to compute ${dEW(w^\star)\over dw^\star}.$ Print out the derivatives each method computes and note their accuracy.
    Suggestion 1: Use a global variable to determine which method to use so you simply write one function not three:
        #include "oxstd.h"
        #import "maximize"
        decl method;  //0=IMR, 1=GQ, 2=MC
        EWstar(wstar,aEW,G,H)   //compute EW* in the form required by Num1Derivative
        
    Suggestion 2: Inside EWstar() you can use if () else if () else to selection which method to compute, or learn to use Ox's switch_single() statement:
        switch_single(method) {
            case 0:   // put IMR code here
        
            case 1:   // put GQ code here
        
            case 2:   // put MC code here
        
            } 
        
    Suggestion 3: use a loop inside main() over methods:
            for(method=0;method<3;++method) {   //sets the global variable used in EWstar
                    wstar = 1.0;
                    Num1Derivative(EWstar,&wstar,&dEW);
                    println("method: ",method," dEW/dw*: ",dEW);
                    }