Announcement

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

  • Creating a variable with a data from another dataset

    I have two dataset. I need to fill (or generate) the variable Priceintargetpricedate in dataset one (Target_Prices).

    Dataset one (Target_Prices), with the follow variables:

    CompanyId ReleaseDate TargetPrice DateTargetPrice Priceintargetpricedate
    101 31/01/2014 30.00 31/12/2014


    Dataset two (Prices), with the follow variables:

    CompanyId Date Price
    101 01/12/2014 28.00
    101 02/12/2014 26.50
    101 03/12/2014 27.00
    .
    .
    .
    .
    101 30/12/2014 32.00
    101 31/12/2014 31.50
    101 02/01/2015 30.00
    .
    .
    .

    Using CompanyId and DateTargetPrice from dataset one, I want to get the price from dataset two and put this in variable Priceintargetpricedate.

    Thanks!

  • #2
    You need merge.

    Code:
    ren DateTargetPrice Date
    merge m:1 CompanyId Date using DatasetTwo.dta, keep(1 3)
    ren DateTargetPrice Date
    ren Price Priceintargetpricedate
    Then check the variable _merge for unmatched data and drop it when you are done.

    Jean-Claude Arbaut

    Comment

    Working...
    X