pasterego.blogg.se

Tostring stata
Tostring stata











The values in _n=1 (line 1 of the data) are the following: var1 and var2 are string variables, while var3 is numeric. As example, suppose we have the variables var1, var2, and var3. In Stata, this can be done by using either -gen- or -egen. To concatenate is to join the characters of 2 or more variables from end to end. PSGC codes are available at the National Statistical Coordination Board. It is composed of (in this order) the 2-digit region code, the 2-digit province code, the 2-digit municipality code, and the 3-digit barangay code. Note: The PSGC is a 9-digit code that represents all geographic units in the Philippines - from the largest (region) to the smallest ( barangay or village).

#Tostring stata install#

You may install -nsplit- by typing: "ssc install nsplit" Domingo, Milaor Camarines Sur, Region V (051721019), and the generated codes after the split: Cannery Site, Polomolok, South Cotabato, Region XII (126312024) and Bgy. For example, here are the PSGC codes for Bgy. Nsplit psgccode, digits(2 2 2 3) gen( reg prov mun bgy)Īnother advantage of -nsplit- is that you do not have to worry about leading 0's. By using -nsplit-, the block of codes above can be shortened into a single line as follows: nsplit- creates new numeric variables to split a numeric variable according to digit pattern. But today I found a more convenient way of splitting numbers by using -nsplit- (Dan Blanchette).

tostring stata

In fact, -substr- is all you need if you only need a part of a string, e.g. This is not to downplay the capabilities of -substr. * Thanks to Nick Cox for pointing out a booboo I have committed in an earlier version of the codes above in his comment below */ Tostring psgccode, gen( str_psgc) format("%09.0f") For example, if I want to split the Philippine Standard Geographic Codes (PSGC) into smaller geographical units, I would write the following codes (see note below): For a very long time I have used the string function -substr- to split all sorts of codes into components.











Tostring stata