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]

Re: st: From: Richard Moverare <>

From   Sergiy Radyakin <>
To   "" <>
Subject   Re: st: From: Richard Moverare <>
Date   Mon, 17 Jun 2013 17:04:16 -0400

Perhaps something like this? All list commands are for illustration
only, drop them from the production code when you understand how the
example works.
Best, Sergiy

input str27 a
"234 Used cars, no batteries"
"22 Bottles - unspecifed"
"234 Used cars, no batteries"
"440 N/A"


gen first=substr(a,1,strpos(a," ")-1)
gen last=substr(a,strpos(a," ")+1, strlen(a)-strpos(a," "))

destring first, replace


duplicates drop a, force
sort first
local cmd "label define mylbl "
forval i=1/`=_N' {
  local cmd `"`cmd' `=first[`i']' `"`=last[`i']'"'"'

label values first mylbl

drop last
label list

On Sun, Jun 16, 2013 at 2:16 PM,  <> wrote:
> Dear Statalist,
> I have a small problem that I guess I should be able to solve, but I
> got stuck. I have a string variable that consists of 1-3 numbers,
> space, and then a description. The description varies in terms of
> numer of words and characters.
> What I would like to do is to create a numeric variable where the
> values are the numbers in the beginning of the string and then use the
> rest of the string as a value label. The dataset includes a number of
> duplicates for this specific variable (one of the reason for doing
> this conversion is to make the dataset smaller in size). The first
> part is no problem using -word-, and I can get what I want as a label
> by getting the second word and those that follow, but I got stuck
> defining the labels for the variable.
> The variables looks something like this:
> 234 Used cars, no batteries
> 22 Bottles - unspecifed
> 234 Used cars, no batteries
> 440 N/A
> and so on.
> Any help would be greatly appreciated!
> All the best, Rick
> *
> *   For searches and help try:
> *
> *
> *
*   For searches and help try:

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