Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding update / replace to fmerge #19

Open
felixholub opened this issue Feb 14, 2018 · 9 comments
Open

Adding update / replace to fmerge #19

felixholub opened this issue Feb 14, 2018 · 9 comments

Comments

@felixholub
Copy link

Would it be possible to extend fmerge to allow for update or replace?

@sergiocorreia
Copy link
Owner

Yes. It might involve a bit of Mata work, but I'm a bit pressed on time for the next month or so, so can't promise any update.

For reference (in case you want to try, or maybe for future me), I think it would involve changing line 381:

	// Check that variables don't exist yet
	msg = "{err}merge:  variable %s already exists in master dataset\n"
	for (i=1; i<=cols(deck); i++) {
		var = deck[i]
		if (_st_varindex(var) != .) {
			printf(msg, var)
			exit(108)
		}
	}

Instead of raising an error if the variable exists, when the -update- option is on, you would have to create a tempvar (st_tempvar()?) and then replace row i of varnames_num.

Then, after the Mata code finished running, something like replace original_var = tempvar if mi(original_var)

@felixholub
Copy link
Author

felixholub commented Feb 14, 2018 via email

@aghaynes
Copy link

aghaynes commented Jun 7, 2019

mmerge has some really useful options (e.g. unmatched [unmatched observations to keep - none, both, master, using], umatch [for the case that variables in using are named different to master], uname [add a stuf to variables in using])

Is there any intent to add additional features to fmerge?

@sergiocorreia
Copy link
Owner

Hi Alan,

Can you explain a bit more what these options do? I installed mmerge from SSC but I'm not entirely sure of what unmatched() does that merge's keep() doesn't.

Regarding umatch() it can actually be done through the join command. I actually wrote fmerge as a wrapper to join (which has a more familiar syntax for me). For instance, suppose you have a panel of consumers (where t is the year identifier) and want to add some macro data from a dataset (where year is the year identifier)

With merge, you do:

rename t year
merge m:1 year using "annual_data", keepusing(gdp inflation)
rename year t

With join, you do:

join gdp inflation, from("annual_data") by(t=year)

(Note how the join syntax looks more like the collapse() one, and is more explicit about which variables get added)

@aghaynes
Copy link

aghaynes commented Jul 3, 2019

Hi Sergio,

Ignore my message. You're completely correct - it's all possible with the other options. (the main advantage to mmerge is that its a bit more verbose in it's reporting)

I wasn't aware of join... I think i'll be looking into that a bit more - i have some quite large datasets which take merge/mmerge a long time to combine...

Thanks!!

@luispfonseca
Copy link

@aghaynes mentioned one which, as far as I can see, join doesn't do and could be potentially useful. The uname option allows adding a stub to the variable names of using data. This makes it easy to distinguish which variables were pre-existing and which are new, maybe for comparison.

@sergiocorreia
Copy link
Owner

Agree, that should be useful and simple to implement. That said, uname() doesn't seem like an esy-to-remember option, so maybe stub(), prefix() or sth like that?

@luispfonseca
Copy link

Yes, I agree. Either of these seem fine. stub seems to be commonly used, but I'd say prefix is more intuitive if you've never heard of it.

@ArthurHowardMorris
Copy link

For what it's worth prefix is the pattern used by frget in Stata 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants