Announcement

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

  • Ambiguous abbreviation with $

    Hi there,

    I hope this question is not too basic - I'm working with some do files created by someone else for a number of older datasets and am supposed to be making them work for the newer versions. I'm stumbling upon this:

    Code:
    merge 1:1 variable1 variable2 using "${path}pl.dta", keepusing($pl) keep(match master) nogen
    First of all, I don't think I fully understand what the $ does within the keepusing() command. From googling it seems this usually has to do with a global macro, but I'm not sure that makes sense in this context.

    When I run this, I get an "ambiguous abbreviation" error. Consequently, the same thing happens with the next command:

    Code:
    use variable1 variable2 $pl using "${path}pl.dta", clear
    "variable3 ambiguous abbreviation"

    Can someone please help with this?

    Thanks in advance,
    Franzi
    Last edited by Franzi De; 11 Oct 2023, 06:38.

  • #2
    My guess is $pl is a global macro that contains variable names or abbreviations of variable names. One or more of those do not uniquely identify a variable in the dataset pl.dta.

    You can type

    Code:
    display "$pl"
    or

    Code:
    macro list
    to view the contents of the global macro.

    You should be able identify the offending contents with

    Code:
    use ${path}pl.dta
    foreach varname of global pl {
        capture noisily confirm variable `varname'
    }

    Comment


    • #3
      Originally posted by daniel klein View Post
      My guess is $pl is a global macro that contains variable names or abbreviations of variable names. One or more of those do not uniquely identify a variable in the dataset pl.dta.
      You are right, I found pl where the macros are defined in the do file. I think the problem might be that global pl is interpreted as global plot because pl is an abbreviation for plot? Hence, Stata might think that $pl is an abbreviation for something. Is that a possibility? If yes, how can I fix that if I can't change the name of the dataset?

      edit: sorry, I just realized that there are actually different variables in the data set and the command was indeed ambiguous due to that - I was wrong as I thought the problem is with the name of the dataset and not the variable. Sorry!
      Last edited by Franzi De; 11 Oct 2023, 07:15.

      Comment


      • #4
        No need for apologies.

        For the record:

        Originally posted by Franzi De View Post
        I think the problem might be that global pl is interpreted as global plot because pl is an abbreviation for plot? H
        cannot be the problem because you cannot abbreviate global macro names. In fact, you can only abbreviate commands, options, and variable names.

        Comment


        • #5
          Abbreviating variable names is a recipe for disaster in my opinion (e.g., sometimes code will run even though it's in error and you don't realise it). I -set var abbrev off- in my profile.do to avoid problems.

          Comment

          Working...
          X