Bookmark and Share

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


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

Re: st: Disaggregating the values taken by a Stata variable


From   Maarten Buis <[email protected]>
To   [email protected]
Subject   Re: st: Disaggregating the values taken by a Stata variable
Date   Fri, 31 May 2013 13:39:35 +0200

The easiest solution is to merge on multiple variables, in this case
region sub-region, and PC. That way you don't have to create a new
variables.

If you want to store this data in one variable, then that is typically
done in the form of a string variable. All regions and subregions are
given short (often numeric codes, but stored as strings), and these
are pasted together such that the first x characters identify the
region, the next y characters the subregion, etc.

The second method does work, but it is easy to introduce a bug that
way. So I recommend to just merge on multiple variables.

Hope this helps,
Maarten


On Fri, May 31, 2013 at 1:21 PM,  <[email protected]> wrote:
> Hi,
>
> I would like to know if it is possible to assign more than one value to a Stata variable under the same condition. Here is my problem:
>
> In my dataset, I have a variable called “economic_region”. I would like to:
>
> 1) assign sub-regions to each of these economic regions
> 2) assign Postal Codes (PC) or Forward Sortation Area (FSA: the first three characters of the PC) to each of these sub-regions (in order to be able to do a "many to one" match later).
>
> In other words, I would like to disaggregate these economic regions. Note that I know the list of the sub-regions for a given economic region and I also know the list of the FSA for a given sub-region, but this information is not in my dataset and I would like to include it. If I had the reverse problem (aggregation), it would be easy for me to solve. For ex, suppose that I wanted to create the economic region named Ottawa from three sub-regions: Nepean, Kanata, Rockland, it wouldbe:
>
> gen str10 economic_region = ”Ottawa” if sub_region == “Nepean” | sub_region == “Kanata” | sub_region == “Rockland”
>
> But, I want to disaggregate instead. I have the economic region named Ottawa and I want to create three sub-regions from it: Nepean, Kanata, Rockland. I thought I could do that by assigning multiple values to the variable called sub-region. I know how to assign more than one value to a Stata variable under different conditions, but I don’t know how to assign more than one value to a Stata variable under the same condition (or if this is even possible!).  Can you tell me if it is possible to do that in Stata and how? I would appreciate your help on this matter.
>
> Best,
> Ruolz.
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/



-- 
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany

http://www.maartenbuis.nl
---------------------------------

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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