Today, I will cover a super easy code but extremely useful-
This is a question that I was asked several times by PhD students and master students who were beginning to code or did not how to code.
So how do we extract 6 digit CUSIP from a 9 digit CUSIP.
Use the substr function
gen cusip6=substr(cusip,1,6)
This command will extract 6 characters starting from the first character.
Yes, it is simple 😀
Another common question that I got asked was how to get the 5 digit ZIP code.
gen zip5=substr(zip,1,5)
Of course, you can check the length and make sure that 5 digits are extracted by
gen zip_len=length(zip5)
or you can just do
des zip5
and it should show how many characters it has-
Very sweet and simple command that will save you time-
As always, if you are stuck always google 😀
Thank You Jesus for another blessed day. Let us always be thankful and give You all the glory Amen 😀
Rejoice at all times. Pray without ceasing. Give thanks in every circumstance, for this is God’s will for you in Christ Jesus.
1 Thessalonians 5: 16-18
If you enjoy the content, you can support the blog through clicking the referral links that I use in my life: Acorns, Robinhood, American Express, dropbox, evernote, and Scribd.