How to use if expression in Stata and whats for

(Comments)

So let me tell you some story. 

You need to labeling the data that you are working on, or you need to create a dataset where you want to label things, and you dont know how to do it! It means you need an if expression. The power of if expression is you can exclude the file that you dont want to add! And thats the magic of labeling, the only make you work with the data that is relevant for you. 

As I promise in the video that I will give you the link so here is the link and also the command in Stata for the video above. 

Download the data first 
use http://www.stata-press.com/data/imeus/census2c, clear
list, sep(0)
describe
Practice in generating a new column / variable 
generate urbanized = popurb/pop
summarize urbanized
For example we want to generate variable name urbanized 
replace urbanized = 100*urbanized
How to use the 
1. If expression in range
So if expression can be used in a range. For example hre you want to exclude any small number of popultion. So if can be used to exclude them. 
if expression
to create popularion
generate medagel = medage if pop > 5000
sort state
list state region medagel, sep(0)
using
2. if exp in with indicator boolean
So if you want to make sure that the group is correct. It can work as true false. Here is the example 
generate smallpop = 0
replace smallpop = 1 if pop <= 5000
generate largepop = 0
replace largepop = 1 if pop > 5000
list state pop small pop largepop, sep(0
3. Using if exp by varlist
So if you want to use the boolean with the varlist like, number of variable 
summarize medage marr divr if region==1 cl

Hi, my name is Dimas; I am a data enthusiast. I am writing several chapters related to Big Data, the macroprudential policy effect on the economy, and some economic and IT research. If you are interested in collaborating, please write your email to [email protected]

Thanks for stopping by. All the information here is curated from the most inspirational article on the site.

Also, check out my newest project related to Preset for researcher

Currently unrated

Comments

Riddles

22nd Jul- 2020, by: Editor in Chief
524 Shares 4 Comments
Generic placeholder image
20 Oct- 2019, by: Editor in Chief
524 Shares 4 Comments
Generic placeholder image
20Aug- 2019, by: Editor in Chief
524 Shares 4 Comments
10Aug- 2019, by: Editor in Chief
424 Shares 4 Comments
Generic placeholder image
10Aug- 2015, by: Editor in Chief
424 Shares 4 Comments

More News  »

How to create output gap with Python and Anaconda

Recent news
1 month, 1 week ago

Dignity wrapped in Charity

Recent news
2 months, 3 weeks ago

A reflection of using kanban flow and being minimalist

Recent news

Today is the consecutive day I want to use and be consistent with the Kanban flow! It seems it's perfect to limit my parallel and easily distractedness. 

read more
3 months ago

Morning issue with car and my kind of music

Recent news
3 months, 1 week ago

Podcast Bapak Dimas 2 - pindahan rumah

Recent news

Vlog kali ini adalah terkait pindahan rumah!

read more
3 months, 1 week ago

Podcast Bapak Dimas - Bapaknya Jozio dan Kaziu - ep 1

Recent news

Seperti yang saya cerita kan sebelumnya, berikut adalah catatan pribadi VLOG kita! Bapak Dimas

read more
3 months, 1 week ago

Happy new year 2024 and thank you 2023!

Recent news

As the new year starts, I want to revisit what has happened in 2023. 

read more
3 months, 1 week ago

Some notes about python and Zen of Python

Recent news

Explore Python syntax

Python is a flexible programming language used in a wide range of fields, including software development, machine learning, and data analysis. Python is one of the most popular programming languages for data professionals, so getting familiar with its fundamental syntax and semantics will be useful for your future career. In this reading, you will learn about Python’s syntax and semantics, as well as where to find resources to further your learning.

read more
4 months, 3 weeks ago

More News »

Generic placeholder image

Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base benefits. Dramatically visualize customer directed convergence without