Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: right justifying strings, left padding strings with zeros


From   Clare L Maxwell <[email protected]>
To   statalist <[email protected]>
Subject   st: right justifying strings, left padding strings with zeros
Date   Tue, 22 Nov 2005 21:23:06 -0600

Hello to members of the Stata list. Thank you in advance for having a look at this.

I have a six-column subject identifier coming into Stata from an ASCII file that looks like the following:

B 1
B 120
CCH 7
CCH 23
CCH213
UW 23
UW 232

I want to read in and manipulate these 6 columns so that in the end, I have a str6 variable that looks like this:

B001
B120
CCH007
CCH023
CCH213
UW023
UW232

That is, the first three columns have been right justified and the last three columns have been left-padded with zeros. I have tried various options, but so far, not much luck. I was considering reading them in as six str1 variables and putting things together sort of by brute force, but I thought I'd ask first. Any suggestions on good string manipulations for this problem?

Thank you very much.

Yours truly,
Clare Maxwell




*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index