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

st: RE: Left-aligned string variables

From   "Nick Cox" <>
To   <>
Subject   st: RE: Left-aligned string variables
Date   Tue, 8 Feb 2005 22:51:24 -0000

ds, has(type string) 

foreach v in `r(varlist)' { 
	local type : type `v' 
	local type : subinstr local type "str" "" 
	format `v' %-`type's


Friedrich Huebler

> How does one left-align a string variable if one does not know the
> length of the longest string? I read [U] 15.5 and the -format- entry
> in the Reference Manual but cannot find an answer to my question.
> Take for example the data in the -format- documentation. To
> left-align the variable "state" I manually inspect the storage type
> to identify the length and then change the display format.
> . webuse census10
> . d state
>               storage  display     value
> variable name   type   format      label      variable label
> ------------------------------------------------------------
> state           str14  %14s                   State
> . format state %-14s
> Can this step be automated? My data consists of several right-aligned
> string variables of varying length and I would like all of them to be
> left-aligned. The solution would work ideally in a case when the
> variable names are not known.

*   For searches and help try:

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