https://www.statalist.org/forums ... ble-types-different
The contents of a variable can be stored as either a numeric variable, one where Stata knows to interpret that content as a number, or as simply a "string" of alpabetic or numeric characters, without paying attention to whether it is numeric or not. This is true even for strings of numerals, such as "19432165." In a CSV file, if that string of numbers is enclosed in quotes, Stata will read and interpret it as simply a string of characters *even if those characters are numerals,* and store it as a string variable and not as a numeric variable. The way in which a variable is stored and interpreted is known in computer programming as its "data type." Variables with different data types cannot be matched or compared unless they are made to be of the same type. This issue is not unique to Stata, but in fact is present in all programs, but possibly hidden from the user.
Stata is telling you that in one file, Stata has stored the key variable as a string, and in the other as a numeric variable of type long. (long is a numeric type variable that holds only integers, but which can hold very large "long" ones. See -help datatype-.) It might be that before now, the variable rifisid had always been put into the CSV file as a string, but someone now prepared that file with rifisid as a numeric variable. That sort of mistake is pretty common in the data processing world.
Stata provides functions to create a numeric variable from a string variable containing numerals. See -help destring-. You can take your "using" file, and convert the string version of rifisid to a long variable, save the file, and then do the merge.
Code:
use "Tidy675_2021.dta"
destring rifisid, gen(temp)
rename rifisid rifisid_as_string // keep copy just in case
rename temp rifisid
recast long rifisid
save "Tidy675_2021.dta"
clear
use "YourMasterFile.dta"
merge m:1 rifisid ....
Dates are a specific and complicated case here, where there are many different ways to use a string to represent a date, and many different ways to store the numeric information of a date. That's a difficult topic, best left aside for the moment.
Last edited by Mike Lacy; 27 May 2021, 15:20. Reason: Forgot to illustrate "clear"