Announcement

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

  • Need help with the postfile command

    Hello,

    I'm trying to use the postfile command but everytime i try to execute it it gives me a error message i dont know how to fix.

    Code:
    postfile Microanalysis countryid N beta_erwerbslos se_erwerbslos beta_cage se_cage using "results_micro.dta", replace
    forvalues i = 1/16 { 
    regress ihealth erwerbslos c.cage if countryid == `i'  
    mat results = r(table)                    
    local countryid = countryid                
    local N = e(N)                            
    local beta_erwerbslos = results[1,1]    
    local se_female = results[1,2]           
    local beta_cage = results[2,1]            
    local se_cage = results[2,2]            
    post Microanalysis (`i') (`N') (`beta_erwerbslos') (`beta_cage') (`se_erwerbslos') (`se_cage') 
    }
    postclose Microanalysis
    The Error Message it gets me is: invalid syntax
    post: above message corresponds to expression 5, variable beta_cage

    I hope anybody can help me.

    Greetings
    Bryan


  • #2
    I see one error in your code, but it's not the one generating the "invalid syntax" error. The order of (`beta_cage') and (`se_erwerbslos') are different in your -postfile- and -post- commands.

    I don't see anything obviously wrong with your syntax. (Someone else might.) I'd suspect that the local beta_cage is coming up missing, for whatever reason. To diagnose this, I'd put in a -mat list results- command to check its content, and a -set trace on- command right before the -post- command. Then you can see the actual content of the -post- command when it fails, which you can post back here as needed.
    Last edited by Mike Lacy; 11 Jan 2020, 08:36.

    Comment


    • #3
      Also, the coefficients are on row one of the r(table) matrix so you should have
      Code:
      ...
          local beta_erwerbslos = results[1,1]
          local beta_cage = results[1,2]   
      ...

      Comment


      • #4
        The effect of
        Code:
        local countryid = countryid
        is to set the local macro countryid to the value of the variable countryid in the first observation. You make no use of the local macro countryid, so you can just omit that command.

        The cause of your syntax error is subtle. You have the following two commands in your code, which I have placed side-by-side and added spaces for easier comparison.
        Code:
        postfile Microanalysis   countryid   N     beta_erwerbslos     se_erwerbslos   beta_cage         se_cage   using "results_micro.dta", replace
        post     Microanalysis (`i')       (`N') (`beta_erwerbslos') (`beta_cage')   (`se_erwerbslos') (`se_cage')
        We see now that you have gotten you post command in a different order than your postfile command, so the result posted in the "variable beta_cage" - which refers to the variable definitions in the postfile command, not to the names of the local macros in the post command - would be the value of the local macro se_ewerbslos. As Mike speculated, no such local macro existed - you defined se_female.

        Combining this problem with the problem noted in post #3, we see that where you have
        Code:
        local beta_erwerbslos = results[1,1]    
        local se_female = results[1,2]          
        local beta_cage = results[2,1]            
        local se_cage = results[2,2]            
        post Microanalysis (`i') (`N') (`beta_erwerbslos') (`beta_cage') (`se_erwerbslos') (`se_cage')
        you need instead
        Code:
        local beta_erwerbslos = results[1,1]    
        local se_erwerbslos = results[2,1]          
        local beta_cage = results[1,2]            
        local se_cage = results[2,2]            
        post Microanalysis (`i') (`N') (`beta_erwerbslos') (`se_erwerbslos') (`beta_cage') (`se_cage')
        Last edited by William Lisowski; 11 Jan 2020, 18:59.

        Comment

        Working...
        X