Stata Basics 6: Convert string var to numeric var destring encode (English version)

Опубликовано: 11 Февраль 2026
на канале: Dr. Bob Wen (Stata, Economics, Econometrics)
4,454
37

The Stata command "destring" and "encode" could be used to convert string variables to numeric variables. Please download the dataset from:
https://drive.google.com/file/d/1WsMu...

***************************************************
** Convert string variables to numeric variables **
***************************************************

describe
list in 1/5

destring yearstr, generate(year)
describe yearstr year
list yearstr year in 1/5

destring pricestr, generate(price) ignore("$")
describe pricestr price
list pricestr price in 1/5

tab racestr
encode racestr, generate(race)
tab race
label list race

browse

【Some courses on my YouTube channel】
Economics in Real Life:
   • Economics in Real Life  

Solutions to Introductory Econometrics A Modern Approach 7th Edition:
   • Solutions to Introductory Econometrics A M...  

Solutions to Microeconomics Theory and Applications with Calculus 5th Edition:
   • Solutions to Microeconomics Theory and App...  

Introductory Stata:
   • Introductory Stata (2022)  

Introductory Microeconomics:
   • Introductory Microeconomics (2022)  

Five Minute Econometrics:
   • Five Minute Econometrics (Econometrics Tut...  

Five Minute Stata:
   • Stata Tutorials  

【國語Mandarin】現實生活中的經濟學:
   • 【Mandarin國語】現實生活中的經濟學  

【粵語Cantonese】現實生活中的經濟學:
   • 【Cantonese粵語】現實生活中的經濟學  

【粵語Cantonese】微觀經濟學基礎:
   • 粵語Cantonese微觀經濟學基礎2022  

【國語Mandarin】五分鐘計量經濟學:
   • 【Mandarin國語】五分鐘計量經濟學(計量經濟學輔導)  

【粵語Cantonese】五分鐘計量經濟學:
   • 【Cantonese粵語】五分鐘計量經濟學(計量經濟學輔導)  

On the Road:
   • On the Road  

Become a Supporter of the channel ($2.99) to get PDF transcripts for
1. Solutions to Microeconomics Theory and Applications with Calculus 5th Edition,
2. Solutions to Introductory Econometrics A Modern Approach 7th Edition,
3. Introductory Stata (2022), and
4. Introductory Microeconomics (2022).
   / @bobwenecon  

My free online Stata course on Alison:
https://alison.com/course/introductor...