Announcement

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

  • create dataset/frame from previous collect result

    hi,

    Is there any way to create a new frame from the previous collect result:

    Code:
    . clear
    
    . sysuse auto
    (1978 automobile data)
    
    . collect clear
    
    . collect: qui reg price mpg rep78 headroom weight length turn displacement gear_ratio
    
    . collect layout (colname) (result[_r_b]) (), name(default)
    
    Collection: default
          Rows: colname
       Columns: result[_r_b]
       Table 1: 9 x 1
    
    ------------------------------------
                           | Coefficient
    -----------------------+------------
    Mileage (mpg)          |   -117.2946
    Repair record 1978     |    742.5576
    Headroom (in.)         |   -594.5623
    Weight (lbs.)          |    3.935387
    Length (in.)           |   -74.93533
    Turn circle (ft.)      |   -208.5507
    Displacement (cu. in.) |    16.98242
    Gear ratio             |    1645.675
    Intercept              |    10076.63
    ------------------------------------

    desired new frame:

    Code:
    . list
    
         +---------------------------------+
         |                  var   coeffi~t |
         |---------------------------------|
      1. |         Mileage(mpg)   -117.295 |
      2. |     Repairrecord1978    742.558 |
      3. |        Headroom(in.)   -594.562 |
      4. |         Weight(lbs.)    3.93539 |
      5. |          Length(in.)   -74.9353 |
         |---------------------------------|
      6. |      Turncircle(ft.)   -208.551 |
      7. | Displacement(cu.in.)    16.9824 |
      8. |            Gearratio    1645.68 |
      9. |            Intercept    10076.6 |
         +---------------------------------+

    thanks,


  • #2
    There is no collect command that will produce a Stata dataset or frame from a given layout. However, with the above example, you can export to Markdown, then use import delimited to convert the exported table into a Stata frame.

    Here is some code that does this.
    Code:
    sysuse auto
    
    collect: qui reg price mpg rep78 headroom weight length turn displacement gear_ratio
    
    collect layout (colname) (result[_r_b]) (), name(default)
    
    * hide the column title so the Markdown only contains the row headers
    * and coefficient values
    collect style header result, level(hide)
    collect preview
    
    collect export table.markdown, replace
    * verify the columns are simply row headers and coefficient values
    type table.markdown
    
    frame create results
    frame results {
        import delimited junk1 xvar coef junk2 using table.markdown, delimiter("|")
        drop junk?
        describe
        list
    }
    Here is the output from describe and list.
    Code:
    .         describe
    
    Contains data
     Observations:             9
        Variables:             2
    ------------------------------------------------------------------------------------------------
    Variable      Storage   Display    Value
        name         type    format    label      Variable label
    ------------------------------------------------------------------------------------------------
    coef            str24   %24s
    result          float   %9.0g
    ------------------------------------------------------------------------------------------------
    Sorted by:
         Note: Dataset has changed since last saved.
    .         list
    
         +--------------------------------------+
         |                     coef      result |
         |--------------------------------------|
      1. |  Mileage (mpg)             -117.2946 |
      2. |  Repair record 1978         742.5576 |
      3. |  Headroom (in.)            -594.5623 |
      4. |  Weight (lbs.)              3.935387 |
      5. |  Length (in.)              -74.93533 |
         |--------------------------------------|
      6. |  Turn circle (ft.)         -208.5507 |
      7. |  Displacement (cu. in.)     16.98242 |
      8. |  Gear ratio                 1645.675 |
      9. |  Intercept                  10076.63 |
         +--------------------------------------+

    Comment

    Working...
    X