Announcement

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

  • Is it possible to feed nlcom with estimates in a vector and covariance in a matrix

    Hi
    I would like to feed my own estimates and covariance into nlcom.
    Is that possible?

    Among other things I've unsuccessfully tried code like:
    Code:
    ereturn clear
    
    matrix b = 1.2039728, 1.0861898, 2.2012326
    
    matrix V = .63333333, .38333333, .38333333
    matrix V = V \ .38333333, .56388889, .38333333
    matrix V = V \ .38333333, .38333333, .39380187
    
    capture program drop epost_bv
    program define epost_bv, eclass
        args b V
        ereturn b = `b'
        ereturn b = `V'
    end
    
    epost_bv b V
    nlcom
    Here I get an "invalid syntax" error in epost_bv.
    But a sollution does not need to be build on this code. It is just showing my current path.

    Looking forward to her from you
    Kind regards

    nhb

  • #2
    I think the problem is that you are expecting -ereturn- to figure out that b and V are matrices. The syntax should be:

    Code:
    ereturn matrix b = `b'
    ereturn matrix V = `V'
    Note: I assume that your original -ereturn b = `V'-, in addition to lacking the word -matrix- is a typo: otherwise you are just overwriting e(b), and with a matrix that will have the wrong dimensions for your purposes.
    Last edited by Clyde Schechter; 24 Feb 2015, 08:38. Reason: Correct typo.

    Comment


    • #3
      Hi
      Sorry, tried to reproduce the code from memory.
      The original code had matrix in the ereturn's, like:
      Code:
      . ereturn clear
      
      . 
      . matrix b = 1.2039728, 1.0861898, 2.2012326
      
      . 
      . matrix V = .63333333, .38333333, .38333333
      
      . matrix V = V \ .38333333, .56388889, .38333333
      
      . matrix V = V \ .38333333, .38333333, .39380187
      
      . 
      . capture program drop epost_bv
      
      . program define epost_bv, eclass
        1.     args b V
        2.     ereturn matrix b = `b'
        3.     ereturn matrix V = `V'
        4. end
      
      . 
      . epost_bv b V
      invalid syntax
      r(198);
      Kind regards

      nhb

      Comment


      • #4
        OK. I haven't done this in a long time, so I forgot a lot of the details.

        You can't use -ereturn matrix-... to post e(b) and e(V). You have to use -ereturn post- for that. Also, the matrices have to have row and column names that match variable in the data set in order to be valid e(b) and e(V) matrices. (That's not just Stata being fussy: in order to use these things for -predict- or -nlcom- and the like, it has to know which coefficients and covariance estimates correspond to which variables.)

        This works:
        Code:
        clear*
        
        capture program drop epost_bv
        program define epost_bv, eclass
          args b V
          ereturn post `b' `V'
         end
         
        sysuse auto
         
        matrix b = 1.2039728, 1.0861898, 2.2012326
        matrix colnames b = mpg headroom _cons
        
        
        matrix V = .63333333, .38333333, .38333333
        
        matrix V = V \ .38333333, .56388889, .38333333
        
        matrix V = V \ .38333333, .38333333, .39380187
        matrix colnames V = mpg headroom _cons
        matrix rownames V = mpg headroom _cons
        
        matrix list b
        matrix list V
        
        epost_bv b V
        ereturn list
        matrix list e(b)
        matrix list e(V)

        Comment


        • #5
          Hi Clyde
          Thank you for your effort.
          I did read about -ereturn post-, but I couldn't get it to work.
          Properly because of the name issue you mention.

          My case is however that I only have estimates and a covariance matrix and I was hoping that I could use -nlcom- to look at transformations of these variables/estimates.
          Kind regards

          nhb

          Comment


          • #6
            Well, then in that case, just create a data set with a single observation with 2 variables having arbitrary (or even missing) values and then use the same approach, using -nlcom- however you like afterward:

            Code:
            clear*
            
            capture program drop epost_bv
            program define epost_bv, eclass
             args b V
             ereturn post `b' `V'
            end
             
            set obs 1
            gen var1 = .
            gen var2 = .
             
            matrix b = 1.2039728, 1.0861898, 2.2012326
            matrix colnames b = var1 var2 _cons
            
            matrix V = .63333333, .38333333, .38333333
            matrix V = V \ .38333333, .56388889, .38333333
            matrix V = V \ .38333333, .38333333, .39380187
            matrix colnames V = var1 var2 _cons
            matrix rownames V = var1 var2 _cons
            
            epost_bv b V
            ereturn list
            matrix list e(b)
            matrix list e(V)
            
            nlcom _b[_cons]*sin(_b[var2])-exp(_b[var1])

            Comment


            • #7
              Hi Clyde
              Thank you very much.
              I'll try that
              Kind regards

              nhb

              Comment

              Working...
              X