Announcement

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

  • ereturn post a vector as a pseudovariable like e(sample)

    Dear Statalist,

    I would like to define an e-class program but have no idea how to -ereturn- a pseudovariable (xx in my example) like the -e(sample)-. Such a pseudovariable would be used in the following post-estimation command so I tried to use -eret post-. But I couldn't find how to do it from the help file for -eret-.

    Any suggestions are appreciated!

    Kind regards,
    Yugen


    Code:
    // x = [1,2,3,4,5,6]
    // y = [1,1,1,1,1,1]
    
    clear all
    
    program define myprograme 
    
    args y x 
    
    marksample touse 
    
    preserve
    
    quietly: keep if `touse'
    
    qui: gen xx = x-3
    qui: replace xx = 0 if x<0
    
    /* some operations on y and x and xx */
    
    restore 
    
    // ereturn xx and get a psuedovariable like e(sample) 
    
    end

  • #2
    I don't think it's possible to ereturn a variable......... right?

    Comment


    • #3
      I have never heard the terminology "pseudovariable" and I do not quite understand the question. e(sample) is a function I think.

      What I can say is that what you are trying to do (which I do not completely understand) probably cannot be done your way with -preserve/restore-.

      At this thread here #3 https://www.statalist.org/forums/for...ile-is-so-fast
      Daniel made the good point that when you do -preserve/restore- you lose track of your sample.

      Comment


      • #4
        Dear Jared and Joro, thanks for your replies!

        1. "pseudovariable" is from the book An introduction to Stata Programming (2nd Ed) by Christopher Baum. Page 94 -e(sample)- is called a Stata "pseudovariable". Footnote 7 writes " Although -ereturn list- output describe -e(sample)- as a function, it is perhaps better considered a variable, albeit one that does not appear in the dataset". Since I don't want to make any changes to my dataset, I need to generate a "pseudovariable" like -e(sample)- which is actually an ereturn function from Stata documentation.

        2. The program is used to calculate a local linear estimation around a specified point. I would like to store the linear weights say w_i on each observation (x_i, y_i). Then the estimator is given by \sum_i (w_i*y_i) where w_i is a function of {x_1 .. x_n} and will be used in one post-estimation command for plotting.
        Last edited by Yugen Chen; 10 Aug 2022, 11:57.

        Comment

        Working...
        X