Announcement

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

  • Error: invalid name r(198);

    Hi everyone,

    I'm writing this function which helps to generate a one to one mapping of two identifiers by the help of their firm names' start and end dates.

    cap prog drop create_unique_match
    prog def create_unique_match

    args unique_firm min_date_uniq max_date_uni count_firm min_date_c max_date_c

    gen tag_date = 1 if (`min_date_uni' >= `min_date_c' & `min_date_uni' <= `max_date_c')
    replace tag_date = 1 if (`max_date_uni'>=`min_date_c' & `max_date_uni'<=`max_date_c')
    replace tag_date = 0 if mi(tag_date)
    bys `unique_firm': egen flag_date = max(tag_date)
    keep if tag_date==flag_date


    bys `unique_firm': egen max_simi_score = max(simi_score)
    keep if simi_score==max_simi_score

    duplicates drop `unique_firm', force

    end

    and then I ran the following code:
    create_unique_match assignee_id min_ee_name_dt max_ee_name_dt permco min_listed_dt max_listed_dt

    Then it reports:
    <=max_listed_dt invalid name
    r(198);


    But if I go back to my data without using the function but instead:
    local min_date_uni min_ee_name_dt
    local max_date_uni max_ee_name_dt
    local min_date_c min_listed_dt
    local max_date_c max_listed_dt

    gen tag_date = 1 if (`min_date_uni' >= `min_date_c' & `min_date_uni' <= `max_date_c')
    it doesn't report any error.

    Could anybody help me with this? Many thanks!

    Best,
    Luman

  • #2
    You can't abbreviate local macro names. With your args statement you created a local macro with name min_date_uniq and so min_date_uni is at best the name of a different local macro. As it doesn't exist, the macro reference doesn't produce the result you want.

    Change the name to
    min_date_uni and things should work better.

    Strictly, you're writing a program defining a command; neither is a function in Stata terms.

    Comment


    • #3
      Thank you so much Nick! I didn't realize this. And also thank you for correcting me with the Stata terms

      Comment

      Working...
      X