Announcement

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

  • Efficient way to create a local of omitted/used variables after a regression?

    I am trying to generate a local with all the omitted variables or the selected variables of a regression. I only do the regression to know if any variable needs to be omitted. But if you can give me another idea the regression is irrelevant. All my variables are in a local called biglist.

  • #2
    I'm not sure what you are doing. Can you give us a specific example? Here are some examples that might help you.

    Code:
    local big_list "a b c d e f g h i j k l m n o p"
    local small_list "c j b m k"
    local leftover: list big_list-small_list
    
    noi di "`leftover'"
    
    
    **OR
    
    sysuse auto, clear
    unab big_list: _all
    reg price rep78 mpg turn foreign
    local reg=e(cmdline)
    di "`reg'"
    local cmd=e(cmd)
    di "`cmd'"
    local reg_vars: list reg - cmd
    di "`reg_vars'"
    local left_vars: list big_list - reg_vars
    di "`left_vars'"
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Here is an example.
      sysuse auto, clear
      gen rep79=rep78
      local biglist= "rep78 rep79 mpg turn foreign"
      reg price `biglist'
      local omitted= ?????

      And then if I write this:
      di "`omitted'"

      I want this:
      rep78

      Comment


      • #4
        There are other ways of doing this, including using regular expressions on the matrix column stripe. This is the way that StataCorp suggests in this FAQ (link):

        Code:
        sysuse auto, clear
        gen rep79=rep78
        local biglist= "rep78 rep79 mpg turn foreign"
        reg price `biglist'
        
        
        local coln : colnames e(b)            //get the col names from the B matrix
        foreach var of local coln {            //loop thru each
            _ms_parse_parts `var'            //_ms_parse_parts tells if it is omitted
            if !`r(omit)' {                    
                local list `list' `var'        //if not omitted, add to list
            }    
        }
        local list : subinstr local list "_cons" ""   //edit out the constant
        local olist : list biglist-list                //omitted is biglist - non-omitted
        display "non-omitted variables: `list'"
        display "the omitted variables: `olist'"
        You might get some idea additional ideas from elsewhere.
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment

        Working...
        X