Announcement

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

  • Saving margins results in a program to use it in simulate

    Dear all,

    I have written the following program

    Code:
    program define myprog1
    
    replace pseudoclass = irecode(runiform(),prob_1, prob_1 + prob_2, prob_1 + prob_2 + prob_3)
    reg dep_var i.trial##i.pseudoclass
    margins i.trial, at(pseudoclass=(1(1)3)) 
    end
    Now I want to conduct a simulation using the results of margins.

    However, I can not see in the margins help file how to refer to the prdicted values.

    If I run e.g.
    Code:
    simulate _se _b, reps(100): myprog1
    It worlks perfectly.

    However, If I run something like

    Code:
    simulate _margins, reps(100): myprog1
    I get the error message
    at values for factor pseudoclass do not sum to 1
    an error occurred when simulate executed myprog1
    Which does not make any sense to me as at values are not supposed to sum up to 1

    Can anyone help me with retriving the predicted values.

    Many Thanks

  • #2
    Sorry, there was an error in my code. The correct program code is
    Code:
    program define myprog1 
     replace pseudoclass = irecode(runiform(),prob_1, prob_1 + prob_2, prob_1 + prob_2 + prob_3) reg dep_var i.trial##i.pseudoclass margins trial, at(pseudoclass=(0(1)2))  end
    However, for
    Code:
    simulate _margins, reps(100): myprog1
    I now get the error message
    _margins not found
    error in expression: _margins
    While, at least to my understanding, _margins sould be available in (r)

    Comment


    • #3
      Adding "post" in the margins command and refering to _b solved the problem.
      Code:
       
       program define myprog1  replace pseudoclass = irecode(runiform(),prob_1, prob_1 + prob_2, prob_1 + prob_2 + prob_3)  reg dep_var i.trial##i.pseudoclass  margins trial, at(pseudoclass=(0(1)2)) post  end simulate _b, reps(100): myprog1
      Sorry for the confusion

      Comment

      Working...
      X