Announcement

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

  • Merge dataset without changing the order (sorting) of the master dataset

    Hi,

    I would like to merge by "var" which is a string variable without changing the sorting of the master dataset. The idea behind it is that I have (string) summary statistics and I would like to append further financial metrics to it.

    This is from outreg2:
    Code:
    v1    v2    v3    v4    v5    v6    v7    v8    v9
        (1)    (2)    (3)    (4)    (5)    (6)    (7)    (8)
    VARIABLES    N    mean    sd    min    p50    max    skewness    kurtosis
                                    
    BTC    61.000000    -0.002955    0.088972    -0.329439    -0.010461    0.265058    -0.279037    6.248104
    mkt    61.000000    -0.001710    0.028785    -0.093254    0.000000    0.055102    -0.719422    3.691702
    priceforecast    61.000000    0.008227    0.074687    -0.171325    0.005751    0.212946    0.024269    4.022328
    pricemom    61.000000    0.007419    0.084524    -0.258553    0.006976    0.212946    0.017151    3.950582
    pricedirection    61.000000    0.006597    0.077920    -0.155021    0.012606    0.212946    0.058501    3.048849
    codeupgrade    61.000000    0.005103    0.076297    -0.239815    0.008471    0.212946    -0.181075    4.418395
    futurevspast    61.000000    0.003999    0.080698    -0.163252    0.002805    0.212946    0.260134    3.064196
    hodl    61.000000    0.003862    0.080947    -0.239815    0.005570    0.232762    -0.235608    3.781521
    violence    61.000000    0.003279    0.081757    -0.136910    0.018439    0.230327    0.171295    3.099122
    combo    61.000000    0.005498    0.058157    -0.119731    0.002235    0.215777    0.746282    5.205468
    I am trying to merge using "table3_order.dta":
    Code:
    n    var
    1    BTC
    2    mkt
    3    violence
    4    hodl
    5    futurevspast
    6    codeupgrade
    7    pricedirection
    8    pricemom
    9    priceforecast
    10    combo
    with the following code:
    Code:
    rename v1 var
    merge m:1 var using table3_order.dta, sorted force
    When I merge, the outreg2 output table gets messed up. Is there a clean way to do this? Variables "var" change at each iteration of the backtesting, so I need to get everything automated... Please help. Thanks!

  • #2
    What you want might possibly be done by the methods you are trying to use. The approach would likely be to create a variable(s) that will mark the desired sort order, perhaps by referring to _n, and then use that variable to sort as needed. For example, a trick as simple as this might help:
    Code:
    gen int MySortOrder = _n
    ... do whatever merging etc. you want.
    sort MySortOrder
    However, I don't understand very well what you want, and I suspect others won't either. Showing several -dataex- examples would help people help you: One for your material from -outreg2-, one for the file to be merged, and one for what you want as a result. With what you have presented here, *we* would have to make the effort to convert your outreg2- material into a Stata file, and it's easier for us if you do that first. If you can't do easily do that, then I think it would be better to take a step back, and describe to us the raw data you have, and the result you want (with examples, of course). I'm inclined to suspect that producing results using the user-written program -outreg2- is not likely to provide the easiest solution to what you want. (Among other difficulties, I'd note that I don't think there are very many users of -outreg2- anymore.)

    Comment

    Working...
    X