Dear Statalist,

I've came across a problem I couldn't solve.

I have a dataset indicting information on firms, in a hierarchical mode: Parent, subsidiary, 2nd rank subsidiary, 3rd rank subsidiary, with advertising data, at the yearly level, by media type (TV, Radio etc.) Data is organised as wide.

Here is an example:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str49 parent str45 subsidiary str100(advertiser brand) str15 media double(spend_1995 spend_1996 spend_1997 spend_1998 spend_1999 spend_2000 spend_2001)
"1-800-flowers.com inc" "harry & david" "bear creek corp"        "bear creek corp"        "newspapers"  . . . . .0001     .  .003
"1-800-flowers.com inc" "harry & david" "bear creek gifts store" "bear creek gifts store" "int display" . . . .     .     .     .
"1-800-flowers.com inc" "harry & david" "bear creek gifts store" "bear creek gifts store" "newspapers"  . . . .     . .0028 .0033
"1-800-flowers.com inc" "harry & david" "bear creek gifts store" "bear creek gifts store" "spot tv"     . . . .     .     .     .
"1-800-flowers.com inc" "harry & david" "bear creek re dev"      "bear creek re dev"      "int display" . . . .     .     .     .
end
Secondly,

I have another dataset showing me if/when companies merged/acquired one another.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float purchase_year str118 product_name str67 changed_from str50 changed_to
2006 "levitra & viagra drugs/toiletries dr" "parent unknown"           "bayer corp/glaxosmithkline plc"
2006 "red bull energy drink"                "energy food & drinks inc" "red bull gmbh"                
2006 "red bull gmbh recruitment"            "red bull"                 "red bull gmbh"                
2006 "red bull air race"                    "s&p co"                   "red bull gmbh"                
2006 "red bull copilot online"              "s&p co"                   "red bull gmbh"                
2006 "red bull dragster day"                "s&p co"                   "red bull gmbh"                
2006 "red bull driver search"               "s&p co"                   "red bull gmbh"                
2006 "red bull dvd&cnqr evnt"               "s&p co"                   "red bull gmbh"                
2006 "red bull flugtag"                     "s&p co"                   "red bull gmbh"                
2006 "red bull giants of rio"               "s&p co"                   "red bull gmbh"                
end

The problem I'm having is that currently the first dataset counts spending for parents, even before they purchased their subsidiaries. Meaning, it retroactively calls all spending done in year 1997, even if the parent only bought the subsidiary in 2000.

Therefore, I need to include the relevant information from the second dataset to the first dataset, but I don't want to merge these datasets, as that will involve a m:m merge.

My solution is the following:

forvalues q = 1995/"purchase_year" {
replace spend_`q' = . ///
if (strpos(parent, "firm name")) & (strpos(subsidiary, "firm name")) | ///
(strpos(parent, "firm name")) & (strpos(subsidiary2, "firm name")) | ///
(strpos(parent, "firm name")) & (strpos(subsidiary3, "firm name")) | ///
(strpos(subsidiary, "firm name")) & (strpos(subsidiary2, "firm name")) | ///
(strpos(subsidiary, "firm name")) & (strpos(subsidiary3, "firm name")) | ///
(strpos(advertiser2, "firm name")) & (strpos(subsidiary3, "firm name"))
}


The problem is that I don't know how to input values from dataset 2, while using dataset 1. I've tried using -frame- and other solutions but couldn't find anything that will help me solve this.

Obviously, there is a possibility that there is some simple solution I didn't think of.

Looking forward to your help,

Thank you.