Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73237

Converting a string variable into numeric with values 0, 1 and 2

$
0
0
I have a string variable of auditor names called FSauditor that has a total of 4438 observations. I have generated a new variable called BigFSaudit which, currently, is all zeros (I used the command gen BigFSaudit = 0)

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str112 FSauditor float BigFSaudit
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"BDO "                                                  0
"Ernst & Young"                                         0
"Grant Thornton"                                        0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Galaz, Yamazaki, Ruiz Urquiza, SC"                     0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Beltran, Gris y Asociados S. Civil de R.L"             0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"KPMG"                                                  0
"Ernst & Young"                                         0
"KPMG"                                                  0
"Deloitte & Associes, Ernst & Young Et Autres"          0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Caipo y Asociados"                                     0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"BDO "                                                  0
"Grant Thornton"                                        0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Ernst & Young"                                         0
"KPMG"                                                  0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"BDO "                                                  0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"BDO "                                                  0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"BDO "                                                  0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"KPMG"                                                  0
"Ernst & Young"                                         0
"KPMG"                                                  0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Galaz, Yamazaki, Ruiz Urquiza, SC"                     0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"KPMG"                                                  0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Galaz, Yamazaki, Ruiz Urquiza, SC"                     0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"BDO "                                                  0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"BDO "                                                  0
"BDO "                                                  0
"PricewaterhouseCoopers"                                0
"Galaz, Yamazaki, Ruiz Urquiza, SC"                     0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"BDO "                                                  0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"Galaz, Yamazaki, Ruiz Urquiza, SC"                     0
"KPMG"                                                  0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"KPMG"                                                  0
"ORD Partners"                                          0
"BDO "                                                  0
"Ernst & Young"                                         0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"KPMG"                                                  0
"Medina, Zaldivar, Paredes & Associations"              0
"Ernst & Young"                                         0
"Pannell Kerr Forster"                                  0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Medina, Zaldivar, Paredes & Associations"              0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Associes, Ernst & Young Et Autres"          0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"BDO "                                                  0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Grant Thornton"                                        0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Ernst & Young"                                         0
"KPMG"                                                  0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Middel & Partners"                                     0
"PricewaterhouseCoopers"                                0
"ShineWing (HK) CPA Limited"                            0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Middel & Partners"                                     0
"Shu Lun Pan Certified Public Accountants Co., Ltd"     0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Chaturvedi & Company"                                  0
"De Chakraborty & Sen"                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Mazars, Ernst & Young et Autres"                       0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
".n"                                                    0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"PricewaterhouseCoopers Audit, Ernst & Young et Autres" 0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Auditor General - Thailand"                            0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"BDO "                                                  0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Auditor General - Thailand"                            0
"Deloitte & Touche LLP"                                 0
"Auditor General - Thailand"                            0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"PricewaterhouseCoopers Audit, Ernst & Young et Autres" 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"KPMG"                                                  0
".n"                                                    0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"PricewaterhouseCoopers Audit, Ernst & Young et Autres" 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Mazars, Ernst & Young Audit"                           0
"Ernst & Young"                                         0
"KPMG"                                                  0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Auditor General - Thailand"                            0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Auditor General - Thailand"                            0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young, PricewaterhouseCoopers"                 0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"BDO "                                                  0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Grant Thornton"                                        0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
".n"                                                    0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Grant Thornton"                                        0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
".n"                                                    0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"KPMG"                                                  0
"Xavier BOUSQUET, Deloitte & Associes"                  0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"Grant Thornton"                                        0
"KPMG"                                                  0
"Samjung Public Account Firm"                           0
"Ernst & Young"                                         0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"KPMG"                                                  0
"KPMG"                                                  0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Grant Thornton"                                        0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"KPMG"                                                  0
"KPMG"                                                  0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Ernst & Young"                                         0
"Deloitte & Touche LLP"                                 0
"KPMG"                                                  0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
"PricewaterhouseCoopers"                                0
"PricewaterhouseCoopers"                                0
"Ernst & Young"                                         0
"Ernst & Young"                                         0
".n"                                                    0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche, KPMG "                              0
"PricewaterhouseCoopers"                                0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche LLP"                                 0
"Deloitte & Touche, KPMG "                              0
"PricewaterhouseCoopers"                                0
"KPMG"                                                  0
"Horwath Maroc Audit, Igrec"                            0
end








I want to replace BigFSaudit with 1 if the string var FSauditor has the following values:

Mazars, Ernst & Young et Autres
Mazars, Ernst & Young Audit
Xavier BOUSQUET, Deloitte & Associes
Deloitte & Associados, SROC SA
Deloitte & Associes, Mazars
RSM Ouest,Ernst & Young Atlantique
Auditeurs et Conseils Associes, Ernst & Young
Deloitte & Touche, Grant Thornton
ERNST& YOUNG Audit,Audit Conseil Expertise, SA
Novances-David & Associés, Deloitte & Associés
Diagnostic Revision Counseil,Ernst & Young et Autres
Deloitte Haskins & Sells, Chaturvedi & Shah, Rajendra & Co.
Deloitte Hadjipavlou, Sofianos & Cambanis S.A.
Deloitte Haskins & Sells, G. P. Kapadia & Co.
KPMG Audit, MAZARS
Mazars, PricewaterhouseCoopers Audit
Bellot Mullenbach & Associés, PricewaterhouseCoopers Audit
PricewaterhouseCoopers, Mazars
KPMG Audit, Grant Thornton
Grant Thornton, Ernst & Young et Autres
KPMG S.A, Mazars
PricewaterhouseCoopers Inc, SizweNtsalubaGobodo Inc
RSM Ouest audit, KPMG SA
Deloitte & Associes, Ernst & Young et Autres, Mazars
KPMG Audit, Acorex Audit
KPMG Audit, Fiduciare Metropole Audit
Samson Bélair/Deloitte & Touche s.e.n.c.r.l.
Mazars, KPMG Audit, Deloitte & Associes
Deloitte & Associés, PricewaterhouseCoopers LLP, Mazars
JLS Partner,Deloitte & Associes
H.C. Watt & Company Limited, PricewaterhouseCoopers
AACE Ile-de-France, Ernst & Young Audit
Cabinet Didier Kling & Associés, Deloitte & Associés
Cabinet Denjean, Ernst & Young Audit
KPMG Audit, MB Audit
PricewaterhouseCoopers Audit, Cagnat & Associes
Ernst & Young, Salustro Reydel
PricewaterhouseCoopers, Fidexco France
Saint Honore BK&A, Deloitte & Associés
PricewaterhouseCoopers, Grant Thornton
KPMG Ford Rhodes, Thornton & Co.








Further, I want to replace BigFSaudit with 2 if the string var FSauditor has the following values:

KPMG
Deloitte & Touche LLP
Ernst & Young
PricewaterhouseCoopers
Deloitte & Associes, Ernst & Young Et Autres
PricewaterhouseCoopers Audit, Ernst & Young et Autres
Ernst & Young, PricewaterhouseCoopers
Deloitte & Touche, KPMG
KPMG Inc, PricewaterhouseCoopers Inc
Ernst & Young, KPMG
Deloitte & Touche, PricewaterhouseCoopers





If the value of FSauditor is missing (".n" above in the dataex list), then BigFSaudit should also be .n.



What is the most efficient way to achieve this? I would rather not use lots of -replace....if- statements. I tried using -inlist-, but it does not take more than 10 strings.

Viewing all articles
Browse latest Browse all 73237

Trending Articles