Stata Code related to the loop with bankscope - stata

the code was ok, but in the second time is not working even though the variable is named differently[][Here is a picture of the error that I'm receiving]I'm working on bankscope database and there are some duplicates. Hence, I'm trying to overcome the duplication. I have tried this following code
foreach var of varlist address website phone fax {
qui duplicates tag `var' year cntrycde ///
if `var'~="", gen(dup_entry)
}
However, I kept receiving an error message which says
(invalid name)
r(198)
Can you help to overcome this issue?

Related

Excel formula error with multiple OR statements inside IF

I am trying to create an automated formula that reads the client initials from the cell and outputs a name for who is responsible for that client in another cell.
=IF(OR(A1="JL",A1="JP"), "John", "N/A",IF(OR(A1="RP",A1="RL",A1="RP"), "Doug", "N/A"))
But I get an error when I try to use this code, I am currently using Excel 2007
The error I get is
You've entered too many arguments for this function.
Is there a way to do this that gets around the error?
I have tried adjusting the comma locations and reducing the amount of brackets with no luck.
Or am I using the formula style wrong?

Error when using string variables in the table command

Why does Stata complain with a cryptic error when I use string variables in the table command?
Consider the following toy example:
sysuse auto, clear
decode foreign, g(foreign_str)
table foreign, contents(n foreign_str mean mpg)
This raises an r(111) variable __000002 not found error in Stata 13.1.
Tracing the error tells me that it is trying to run format __000002 %9.0gc and crashing when it does not find the variable. If I switch the order of the variables in the clist, that is i run table foreign, contents(n mpg_rank mean mpg), I get the same error but with __000003 instead of __000002.
So it appears that Stata crashes when it finds the string variable. If I replace the string variable with a numeric variable, the error doesn't occur.
I know it is not meaningful to compute summary statistics on string variables, but counting the number of observations of a string variable (in each group specified by the rowvar) makes perfect sense.
Stata complains because variable __000002 (or __000003 if you change the order) is not created by the collapse command (which is used internally by table) due to the following error:
collapse (count) foreign_str
type mismatch
r(109);
What really happens is not visible to the user because capture is used in combination with collapse and the output from trace confirms that:
- capture collapse `clist' `wgt', by(`varlist' `by') fast `cw'
= capture collapse (count) __000002=foreign_str (mean) __000003=mpg , by(foreign ) fast
There are only provisions for error codes 111 and 135, so the table command continues to run until it hits a wall when it cannot find the aforementioned variables.
Stata 14 and later versions check the variable(s) provided by the user in the contents() option and only accept numeric types, issuing a more informative error message if this is not the case.
It is also worth pointing out that collapse treats strings differently in more recent Stata versions.

Replace cases in one dataset using cases from another file

I have a master data file that contains responses from English, German, and French respondents. The open-ended responses (OER) were sent to translators and they sent us back a file with the original OER and English translation of those. Now I want to replace the "empty" columns reserved for English translation in my master data with the new information.
My approach was:
Create a loop in the translation file:
foreach var of varlist *englishtranslation* {
rename `var' new_`var'
}
Then merge new_`var' into master data using respondent ID.
Replace non-missing cases in blank cols using info in new_`var'.
Drop new_`var'.
However, Stata keeps saying that the new variable names new_`var' are invalid:
You attempted to rename q12_v1_995_oe_englishtranslation to
new_q12_v1_995_oe_englishtranslation. That is an invalid Stata
variable name.
Do you have any recommendation on fixing that error or on another approach?
Many thanks,
EL
Edit: I understand that the variable name length limit is 32 and that variable has exactly 32 characters, hence the error when I tried to rename it. But I need to come up with a systematic way to name these variables because multiple people work on it and I don't want to mess with the agreed organization of the dataset.
Your new name has 36 characters. There's a limit of 32 (with Stata 12 and 13, at least).
An example reproducing your error:
clear
set more off
set obs 1
gen q12_v1_995_oe_englishtranslation = 99
gen new_q12_v1_995_oe_englishtranslation = 10
Solution: make the name shorter.
See help varname for details.
Edit
On your question about renaming:
Try:
rename *englishtranslation *engtrans
See help rename and help rename group for details.

Macros constantly resulting in 'invalid name'

I'm a newcomer to Stata after using R for a long time.
I'm trying to perform any action which involves a macro, such as a loop and it is constantly giving me an invalid name r(198) error.
For example, when I first start up Stata, I enter the following code into the command prompt:
local hello 123
di 'hello'
This results in:
'hello' invalid name
r(198);
Similarly, I try:
forvalues i=1/5 {
display 'i'
}
Which results in the same invalid name error.
I'm obviously doing something fundamentally wrong. I have tried putting the same commands into a do file and running them, but the same thing occurred.
I was wondering if it's something to do with how I'm running the code as this link alludes to, but nothing suggested there worked for me.
I'm running Stata remotely from a server, if that could affect anything.

Crystal report if then help, how to return a string or variable with formula

Relatively new to crystal and I've hit a bit of a snag with a formula.
I'm trying to create a formula that will report out when an RMA was received and how many. If none of the items have been received, I want it to show a message stating such, but if items from the RMA have been received I want it to return the receipt number.
Since a picture is worth a thousands words...
Current report view
I tried using an if then but I don't think you can combine strings with BAQReportResult values.
if {BAQReportResult.RMARcpt.OurReceivedQty}>0 then {BAQReportResult.RMARcpt.RMAReceipt}
After that I tried a variety of else statements but stuck here I am...
Any help is greatly appreciated!
I think you must declare a string type and then assign the value in else part.
Create a Formula and place in the Report, what has to be written in formula will be like:
stringvar text:="";
if {BAQReportResult.RMARcpt.OurReceivedQty}>0 then
text="{BAQReportResult.RMARcpt.RMAReceipt}"
else
text="There are ..."