Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: converting a local of variable names in string variables


From   "Sarah Cohodes" <sarah.cohodes@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: converting a local of variable names in string variables
Date   Mon, 25 Feb 2008 10:52:02 -0500

Hi Johannes,

Try the user installed module -sxpose- by Nick Cox (see:
http://econpapers.repec.org/software/bocbocode/s446402.htm) if you
want to transpose your dataset with string variables.  To install,
type:

ssc install sxpose

Then you can merge on your ID using -merge-; it doesn't matter if the
identification variable you use is string or not.

Good luck,
Sarah

On Mon, Feb 25, 2008 at 10:14 AM, Johannes Geyer <JGeyer@diw.de> wrote:
> Dear Statalist,
>
> I am trying to match a data set of variable idenfifiers (data1) and a data
> set that consists of these variables (data2).
>
> data1:
>
> var id  v1      v2      v3
> 1       jk12    kk14    lk16
> 2       jk24    kk67    lk90
> 3       jk16
> ..
>
> data2:
>
> obs id  jk12    jk24    jk16
> 1       12000   56      1
> 2       12000   71      0
> 3       ...
> ..
>
> now I need to have a procedure that links variable names from data2 with a
> subset "var id" from data1. My idea was to save variable names in a local
> macro, then generate string variables from it and merge it to data1 -
> however, I am not used to strings and I do not know if that is possible.
>
> I tried the following
>
> ******************
> #d;
> use data2.dta, clear;
> qui ds;
> local x "`r(varlist)'";
> qui d;
> local y "`r(k)'";
> di `y';
>
> forvalues no = 1/`y' {;
> gen str61 typ`no' = "";
> local n = `n' + 1;
> local Q: word `n' of `x';
> replace typ`no' = string(`Q');
> };
> ******************
> This ends with the content (not the names) of variables copied as string
> in the new variables - but this is not what I need, I need names only.
>
> I would like to proceed by using the index to reshape and then merge it to
> the other data set. With export and manipulation by hand I might be able
> to solve this problem, but I prefer to have it in Stata.
>
> I appreciate any suggestion on that,
>
> thank you
>
> Johannes
>
>
>
>
>
> ----------------------
> Johannes Geyer
> Deutsches Institut für Wirtschaftsforschung (DIW Berlin)
> German Institute for Economic Research
> Department of Public Economics
> DIW Berlin
> Mohrenstraße 58
> 10117 Berlin
> Tel: +49-30-89789-258
>
> *
> *   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/
>

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index