Announcement

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

  • Selecting column from r(table) based on column name

    Hi all,

    I have an r(table) where the columns have names that stretch over three rows. I want to select one value in the r(table) and save it to a matrix. Normally, I would use:

    mat X=r(table)
    mat Y=X["pvalue",Variable1"]

    which would return the value in row 'pvalue' and column 'variable1'.

    This no longer works now that the name of column variable consists out of 3 lines as can be seen in the sample below:
    (some column and rows were removed for viewing purposes)


    . mat li X
    X[9,16]
    Dep_var: Dep_var: Dep_var: Dep_var: cut1: cut2:
    1b. 2.
    Bin Bin Variable1 Variable2 _cons _cons
    b 1 2.5912676 .89907478 1.0662699 -11.00487 -10.587897
    se . .66428033 .02262727 .04042181 2.0752059 2.0324945
    z . 3.714197 -4.2272772 1.6926192 .b .b
    pvalue . .00020385 .00002365 .09052797 .b .b
    ll . 1.5678475 .85580218 .98991626 -15.072199 -14.571513
    Q: How can I write the value printed in red (.00002365) in a matrix by specifying the column and row names?

    I do not wish to use hardcoded column and row numbers (e.g. mat Y=X[4,3]).

    Thanks,

    - Vincent
    Last edited by Vincent Koppelmans; 19 Sep 2015, 18:40.

  • #2
    For two-part names it works pretty much the same:

    Code:
    clear
    set more off
    
    *----- example data -----
    
    sysuse auto
    
    sureg (price i.foreign weight length) (mpg foreign weight) (displ foreign weight)
    
    matrix rtable = r(table)
    matrix list rtable
    
    *----- what you want -----
    
    matrix myselect = rtable["pvalue","price:1.foreign"]
    matrix myselect2 = rtable["se","mpg:foreign"]
    
    matrix list myselect
    matrix list myselect2
    Check:
    [U] 14.2.2 Two-part names
    You should:

    1. Read the FAQ carefully.

    2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

    Comment


    • #3
      Thanks!

      Comment

      Working...
      X