Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Monte Carlo Simulation and Kernel density graphing

    Hi

    I'm stuck with a monte carlo simulation for testing 5 different models and comparing them at the end.

    This is my current code: I would be extremely grateful for any help as unsure why it isn't working

    ** Generate the observable treatment effect
    gen `Ty0' = gamma_0 + gamma_1* Tage+ gamma_2*Tfemale+ gamma3*Tage*Tfemale+Terror

    gen yobs= Ty0 + TW

    reg Ty0 TW
    ** Store value of beta
    mat beta 'j' [`i',1] = ss1[1,1]

    reg Ty0 TW Tage Tfemale Tfemale*Tage
    ** Store value of beta
    mat beta 'j' [`i',2] = ss2[1,1]

    reg Ty0 TW i.Tage
    ** Store value of beta
    mat beta 'j' [`i',3] = ss3[1,1]

    logit `TW' `Tage'
    predict `pred_prob1' //
    gen `lad'=1/`pred_prob1'^`TW'*(1-`pred_prob1'^(1-`TW'))
    reg Ty0 Tage `lad' [W=`lad']
    mat beta 'j' [`i',4] = ss4[1,1]

    logit `TW' i.`Tage'
    predict `pred_prob2' //
    gen `lad2'=1/`pred_prob2'^`varw'*(1-`pred_prob2'^(1-`varw'))
    reg `y0' `vage' `lad2' [w=`lad2']
    mat beta 'j' [`i',5] = ss5[1,1]
    }
    end

    ** Run the programme R=1000 times
    mat def beta1 = J(1000,2,.)
    set seed 12345
    forvalues i = 1/1000 {
    SIM 'i' 5
    }

    svmat beta1

    ** Summarize each estimators
    sum beta11 beta12 beta13 beta14 beta15

  • #2
    What does "isn't working" mean in your case?

    Maybe the simulate command helps?
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      In the first line of code

      Code:
      gen `Ty0' = gamma_0 + gamma_1* Tage+ gamma_2*Tfemale+ gamma3*Tage*Tfemale+Terror
      you refer to a local macro Ty0. That will work if the local macro has been defined earlier in the code and contains a legal new variable name, but not otherwise.

      Then you refer to Ty0 as a variable name. but commands using it depend on it having been created earlier.

      This two puzzles are perhaps one and the same puzzle, so that the first command should refer to Ty0.

      Comment


      • #4
        Thankyou both Maarten and Nick!

        I tried the SIM code and got a loop together, specifying y0 like you suggested! Worked for my easier regressions so thankyou muchly! However now i see the 'unknown weight type' error in my logit model. I have coded :
        logit `TW' `Tage'
        predict `pred_prob1'
        gen `lad'= 1/((`pred_prob1'^`TW')*((1-`pred_prob1')^(1-`TW')))
        reg `Tyobs' `Tage' [W=`lad']
        [pweight=W]
        *mat beta`j'[`i',4] = _b[`TW']

        but not sure where it has gone worng

        Comment

        Working...
        X