Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Insert spaces into a string variable upto the max length of a variable.

From   Tim Evans <>
To   "" <>
Subject   st: Insert spaces into a string variable upto the max length of a variable.
Date   Thu, 6 Feb 2014 21:34:28 +0000


I'm using Stata 11.2. I have a string variable called 'make' containing the following:


The max string length is 7 (for Lincoln) with the smallest being 3 for AMC.

What I want to do is assess the maximum length of the variable 'make' and then insert extra spaces in order to make the length of each value up to the max. I.e add to the end of Buick two spaces and AMC (4 spaces) and Lincoln (no spaces). 

I need this for when I concatenate the string variable with another string so that the start of the second string component is aligned for all values.

Any help much appreciated

Best wishes


The information contained in the EMail and any attachments is confidential and intended solely and for the attention and use of the named addressee(s). It may not be disclosed to any other person without the express authority of Public Health England, or the intended recipient, or both. If you are not the intended recipient, you must not disclose, copy, distribute or retain this message or any part of it. This footnote also confirms that this EMail has been swept for computer viruses by Symantec.Cloud, but please re-sweep any attachments before opening or saving.

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index